SlideShare a Scribd company logo
1 of 18
DATE:- 26/05/16
Presented By: Nitin Kumar Upadhyay
K.V. Ramgarh Cantt
Region:- Ranchi
What is File and what is the purpose of using a
File?
A file can be defined as bunch of bytes stored
on some storage media.
Files are used to store data permanently in C++.
What is Stream and how I/O Operations takes
place in a file?
A stream is a sequence of bytes or flow of data.
Stream is needed to perform input and output
operations in a file.
What are different types of File Streams?
There are two types of streams.
ofstream :- It is used to write data to a file.
Variable output stream File
ifstream :- It is used to read data from a file.
File input stream variable
To learn Merge and Search operations first we
have to understand file opening modes used for
above said purpose.
Q. What is file opening mode
Ans. File opening Mode defines type of
operations
which we can perform with the file.
For Merge and Search operation following
modes
are used.
ios::out:- It creates a new file for writing.
ios::in :- It opens an existing file for
reading.
Functions/Operators to read/write data from a file.
Functions/Operators to read data from a file.
<<, get( ), getline( ),read()
Functions/Operators to write data to a file.
>>,put( ),write( )
Functions to read and write data from a file.
S.No. Type of Data Function for
Writing data
to a file
Function for
Reading Data
from a file
01 Number << >>
02 char put( ),<< get( ),>>
03 Word << >>
04 String << >>
05 Line/Sentence << get( )
getline( )
06 Record read( ) write( )
To perform search operation in file.
It must be open in ios::in mode and the data must
be read from file as per the type of data or
requirement.
For ex.
(i)Suppose a question is given to count or perform
any operation in file on the basis of alphabets
like counting of vowels or blank spaces etc.
Then data must be read from file using
fstream.get(char_var);
If stream object is f1 and char variable is ch then
f1.get(ch);
To perform search operation in file.
(ii) If question is given to count no of words or
occurrence of a particular word then
Then data must be read from file using
file_stream>>string_var;
If stream object is f1 and string variable is
str then
f1 >> str;
To perform search operation in file.
(iii) if question is given to count no of lines
present in a file.
Then data must be read from file using
file_stream.get(str,no_of_char,delim_char)
If stream object is f1 and string variable is
str then
f1.get(str,80,’n’);
or
f1.getline(str,80,’n’);
To perform search operation in file.
(iv) if question is given to count no of records
Then data must be read from file using
file_stream.read((char *)&o,sizeof(o));
If stream object is f1 and structure
variable/class object is o then
f1.read((char *)&o,sizeof(o));
To perform search operation in a file
implemeted using structure.
For example suppose stu is a structure with
following definition and student.dat is a file
which contains details of students as given
structure.
strcut stu
{ int rollno;
char name[30];
float per;
}s;
then to search record of a student having
name sumit.
void search( )
{ fstream f1;char str[40];
f1.open(“student.dat”,ios::in|ios::binary);
while(!f1.eof( ))
{ f1.read((char *)&s,sizeof(s));
if(strcmp(s.name,”sumit”)==0)
cout<<s.rollno<<s.percentage
}
f1.close( );
}
To add one more record of a student.
void append( )
{ fstream f1;student p;
f1.open(“student.dat”,ios::app|ios::binary);
while(!f1.eof( ))
{ cout<<“Input rollno,name and percentage”;
cin>>s.rollno;gets(s.name);cin>>s.per;
f1.write((char *)&s,sizeof(s));
}
f1.close( );
}
 #include<fstream.h>
 #include <conio.h>
 #include<stdio.h>
 void main( )
 {
 char ch;
 char str[20];
 fstream f1,f2,f3;
 f1.open("abc1.txt",ios::out);
 cout<<"input str";
 gets(str);
 f1<<str;
 f1.close();
 f2.open("abc2.txt",ios::out);
 cout<<"input str";
 gets(str);
 f2<<str;
 f2.close();
 f1.open("abc1.txt",ios::in);
 f2.open("abc2.txt",ios::in);
 f3.open("abc3.txt",ios::app);
 while(!f1.eof())
 { f1.get(ch);
 f3.put(ch);}
 while(!f2.eof())
 { f2.get(ch);
 f3.put(ch); }
 f1.close(); f2.close(); f3.close();
 f3.open(“abc3.txt”,ios::in);
 while(!f3.eof())
 { f3>>(str);
 cout<<str
 }
 f3.close();
File Handling - N K Upadhyay

More Related Content

What's hot (20)

C files
C filesC files
C files
 
Flat Filer Presentation
Flat Filer PresentationFlat Filer Presentation
Flat Filer Presentation
 
5 Structure & File.pptx
5 Structure & File.pptx5 Structure & File.pptx
5 Structure & File.pptx
 
Pf cs102 programming-8 [file handling] (1)
Pf cs102 programming-8 [file handling] (1)Pf cs102 programming-8 [file handling] (1)
Pf cs102 programming-8 [file handling] (1)
 
Switching & Multiplexing
Switching & MultiplexingSwitching & Multiplexing
Switching & Multiplexing
 
Streams and Files
Streams and FilesStreams and Files
Streams and Files
 
Indexing structure for files
Indexing structure for filesIndexing structure for files
Indexing structure for files
 
Mesics lecture files in 'c'
Mesics lecture   files in 'c'Mesics lecture   files in 'c'
Mesics lecture files in 'c'
 
File handling in Python
File handling in PythonFile handling in Python
File handling in Python
 
File handling
File handlingFile handling
File handling
 
Files and file objects (in Python)
Files and file objects (in Python)Files and file objects (in Python)
Files and file objects (in Python)
 
Files in C
Files in CFiles in C
Files in C
 
C programming disk file reading and writing
C programming disk file reading and writingC programming disk file reading and writing
C programming disk file reading and writing
 
File organization 1
File organization 1File organization 1
File organization 1
 
File handling
File handlingFile handling
File handling
 
Python programming : Files
Python programming : FilesPython programming : Files
Python programming : Files
 
Chapter 10.1
Chapter 10.1Chapter 10.1
Chapter 10.1
 
17 files and streams
17 files and streams17 files and streams
17 files and streams
 
File handling-c
File handling-cFile handling-c
File handling-c
 
File handling in vb.net
File handling in vb.netFile handling in vb.net
File handling in vb.net
 

Viewers also liked

UNFE Final Report_v3
UNFE Final Report_v3UNFE Final Report_v3
UNFE Final Report_v3Andre Banks
 
Adele Marra
Adele MarraAdele Marra
Adele MarraMoovents
 
Luca Soranzo
Luca SoranzoLuca Soranzo
Luca SoranzoMoovents
 
Learning analytics support for just-in-time teaching
Learning analytics support for just-in-time teachingLearning analytics support for just-in-time teaching
Learning analytics support for just-in-time teachingraquelm_crespo
 

Viewers also liked (9)

eko2014
eko2014eko2014
eko2014
 
UNFE Final Report_v3
UNFE Final Report_v3UNFE Final Report_v3
UNFE Final Report_v3
 
OPWDD resume Garruto
OPWDD resume GarrutoOPWDD resume Garruto
OPWDD resume Garruto
 
Adele Marra
Adele MarraAdele Marra
Adele Marra
 
Manual del usuario
Manual del usuarioManual del usuario
Manual del usuario
 
Luca Soranzo
Luca SoranzoLuca Soranzo
Luca Soranzo
 
Learning analytics support for just-in-time teaching
Learning analytics support for just-in-time teachingLearning analytics support for just-in-time teaching
Learning analytics support for just-in-time teaching
 
003 cuarto reyesamezquita_helendaniela (1)
003 cuarto reyesamezquita_helendaniela (1)003 cuarto reyesamezquita_helendaniela (1)
003 cuarto reyesamezquita_helendaniela (1)
 
Dossier Beat the Odds
Dossier Beat the OddsDossier Beat the Odds
Dossier Beat the Odds
 

Similar to File Handling - N K Upadhyay

Files in C++.pdf is the notes of cpp for reference
Files in C++.pdf is the notes of cpp for referenceFiles in C++.pdf is the notes of cpp for reference
Files in C++.pdf is the notes of cpp for referenceanuvayalil5525
 
Filesinc 130512002619-phpapp01
Filesinc 130512002619-phpapp01Filesinc 130512002619-phpapp01
Filesinc 130512002619-phpapp01Rex Joe
 
chapter-12-data-file-handling.pdf
chapter-12-data-file-handling.pdfchapter-12-data-file-handling.pdf
chapter-12-data-file-handling.pdfstudy material
 
File management in C++
File management in C++File management in C++
File management in C++apoorvaverma33
 
INput output stream in ccP Full Detail.pptx
INput output stream in ccP Full Detail.pptxINput output stream in ccP Full Detail.pptx
INput output stream in ccP Full Detail.pptxAssadLeo1
 
Introduction to Data Structure : Pointer
Introduction to Data Structure : PointerIntroduction to Data Structure : Pointer
Introduction to Data Structure : PointerS P Sajjan
 
FIle Handling and dictionaries.pptx
FIle Handling and dictionaries.pptxFIle Handling and dictionaries.pptx
FIle Handling and dictionaries.pptxAshwini Raut
 
FILE HANDLING IN C++. +2 COMPUTER SCIENCE CBSE AND STATE SYLLABUS
FILE HANDLING IN C++. +2 COMPUTER SCIENCE CBSE AND STATE SYLLABUSFILE HANDLING IN C++. +2 COMPUTER SCIENCE CBSE AND STATE SYLLABUS
FILE HANDLING IN C++. +2 COMPUTER SCIENCE CBSE AND STATE SYLLABUSVenugopalavarma Raja
 
File handling & basic operation on file in python
File handling & basic operation on file in pythonFile handling & basic operation on file in python
File handling & basic operation on file in pythonishantjaiswal2004
 
Chapter28 data-file-handling
Chapter28 data-file-handlingChapter28 data-file-handling
Chapter28 data-file-handlingDeepak Singh
 

Similar to File Handling - N K Upadhyay (20)

Files in C++.pdf is the notes of cpp for reference
Files in C++.pdf is the notes of cpp for referenceFiles in C++.pdf is the notes of cpp for reference
Files in C++.pdf is the notes of cpp for reference
 
working with files
working with filesworking with files
working with files
 
Files in c++
Files in c++Files in c++
Files in c++
 
Filesinc 130512002619-phpapp01
Filesinc 130512002619-phpapp01Filesinc 130512002619-phpapp01
Filesinc 130512002619-phpapp01
 
chapter-12-data-file-handling.pdf
chapter-12-data-file-handling.pdfchapter-12-data-file-handling.pdf
chapter-12-data-file-handling.pdf
 
Data file handling
Data file handlingData file handling
Data file handling
 
File Handling
File HandlingFile Handling
File Handling
 
File management in C++
File management in C++File management in C++
File management in C++
 
File handling in cpp
File handling in cppFile handling in cpp
File handling in cpp
 
Unit V.pptx
Unit V.pptxUnit V.pptx
Unit V.pptx
 
INput output stream in ccP Full Detail.pptx
INput output stream in ccP Full Detail.pptxINput output stream in ccP Full Detail.pptx
INput output stream in ccP Full Detail.pptx
 
Introduction to Data Structure : Pointer
Introduction to Data Structure : PointerIntroduction to Data Structure : Pointer
Introduction to Data Structure : Pointer
 
file_handling_in_c.ppt
file_handling_in_c.pptfile_handling_in_c.ppt
file_handling_in_c.ppt
 
File handling in c
File handling in cFile handling in c
File handling in c
 
FIle Handling and dictionaries.pptx
FIle Handling and dictionaries.pptxFIle Handling and dictionaries.pptx
FIle Handling and dictionaries.pptx
 
FILE HANDLING IN C++. +2 COMPUTER SCIENCE CBSE AND STATE SYLLABUS
FILE HANDLING IN C++. +2 COMPUTER SCIENCE CBSE AND STATE SYLLABUSFILE HANDLING IN C++. +2 COMPUTER SCIENCE CBSE AND STATE SYLLABUS
FILE HANDLING IN C++. +2 COMPUTER SCIENCE CBSE AND STATE SYLLABUS
 
FILE HANDLING.pptx
FILE HANDLING.pptxFILE HANDLING.pptx
FILE HANDLING.pptx
 
File Handling In C++
File Handling In C++File Handling In C++
File Handling In C++
 
File handling & basic operation on file in python
File handling & basic operation on file in pythonFile handling & basic operation on file in python
File handling & basic operation on file in python
 
Chapter28 data-file-handling
Chapter28 data-file-handlingChapter28 data-file-handling
Chapter28 data-file-handling
 

More from Dipayan Sarkar

introduction to aep arc
introduction to aep arcintroduction to aep arc
introduction to aep arcDipayan Sarkar
 
why focus on adolescents unique needs
why focus on adolescents unique needswhy focus on adolescents unique needs
why focus on adolescents unique needsDipayan Sarkar
 
aep in india milestones, learning, way forward
aep in india milestones, learning, way forwardaep in india milestones, learning, way forward
aep in india milestones, learning, way forwardDipayan Sarkar
 
Softskills - S Fernandez
Softskills - S FernandezSoftskills - S Fernandez
Softskills - S FernandezDipayan Sarkar
 
Project Based Learning- Ashish K Chaurdia
Project Based Learning- Ashish K ChaurdiaProject Based Learning- Ashish K Chaurdia
Project Based Learning- Ashish K ChaurdiaDipayan Sarkar
 
Linux and the Open Source- D Sarkar
Linux and the Open Source- D SarkarLinux and the Open Source- D Sarkar
Linux and the Open Source- D SarkarDipayan Sarkar
 
Sorting Techniques - Govardhan Satish
Sorting Techniques - Govardhan SatishSorting Techniques - Govardhan Satish
Sorting Techniques - Govardhan SatishDipayan Sarkar
 
Application of Stack - Yadraj Meena
Application of Stack - Yadraj MeenaApplication of Stack - Yadraj Meena
Application of Stack - Yadraj MeenaDipayan Sarkar
 
Information Technology Act 2000 - Santosh K Pathak
Information Technology Act 2000 - Santosh K PathakInformation Technology Act 2000 - Santosh K Pathak
Information Technology Act 2000 - Santosh K PathakDipayan Sarkar
 
Universal Gates - Aneesa N Ali
Universal Gates - Aneesa N AliUniversal Gates - Aneesa N Ali
Universal Gates - Aneesa N AliDipayan Sarkar
 
Selection Sort - Vipin Ramola
Selection Sort - Vipin RamolaSelection Sort - Vipin Ramola
Selection Sort - Vipin RamolaDipayan Sarkar
 
Deletion of a Record from a File - K Karun
Deletion of a Record from a File - K KarunDeletion of a Record from a File - K Karun
Deletion of a Record from a File - K KarunDipayan Sarkar
 
Java Databse Connectvity- Alex Jose
Java Databse Connectvity- Alex JoseJava Databse Connectvity- Alex Jose
Java Databse Connectvity- Alex JoseDipayan Sarkar
 
Computer Viruses- B S Kalyan Chakravarthy
Computer Viruses- B S Kalyan ChakravarthyComputer Viruses- B S Kalyan Chakravarthy
Computer Viruses- B S Kalyan ChakravarthyDipayan Sarkar
 
Cloud Computing- Sreehari S
Cloud Computing- Sreehari SCloud Computing- Sreehari S
Cloud Computing- Sreehari SDipayan Sarkar
 

More from Dipayan Sarkar (18)

Relationships
RelationshipsRelationships
Relationships
 
ideal learning space
ideal learning spaceideal learning space
ideal learning space
 
introduction to aep arc
introduction to aep arcintroduction to aep arc
introduction to aep arc
 
why focus on adolescents unique needs
why focus on adolescents unique needswhy focus on adolescents unique needs
why focus on adolescents unique needs
 
aep in india milestones, learning, way forward
aep in india milestones, learning, way forwardaep in india milestones, learning, way forward
aep in india milestones, learning, way forward
 
Softskills - S Fernandez
Softskills - S FernandezSoftskills - S Fernandez
Softskills - S Fernandez
 
Project Based Learning- Ashish K Chaurdia
Project Based Learning- Ashish K ChaurdiaProject Based Learning- Ashish K Chaurdia
Project Based Learning- Ashish K Chaurdia
 
Linux and the Open Source- D Sarkar
Linux and the Open Source- D SarkarLinux and the Open Source- D Sarkar
Linux and the Open Source- D Sarkar
 
Sorting Techniques - Govardhan Satish
Sorting Techniques - Govardhan SatishSorting Techniques - Govardhan Satish
Sorting Techniques - Govardhan Satish
 
Application of Stack - Yadraj Meena
Application of Stack - Yadraj MeenaApplication of Stack - Yadraj Meena
Application of Stack - Yadraj Meena
 
Information Technology Act 2000 - Santosh K Pathak
Information Technology Act 2000 - Santosh K PathakInformation Technology Act 2000 - Santosh K Pathak
Information Technology Act 2000 - Santosh K Pathak
 
Universal Gates - Aneesa N Ali
Universal Gates - Aneesa N AliUniversal Gates - Aneesa N Ali
Universal Gates - Aneesa N Ali
 
Selection Sort - Vipin Ramola
Selection Sort - Vipin RamolaSelection Sort - Vipin Ramola
Selection Sort - Vipin Ramola
 
Deletion of a Record from a File - K Karun
Deletion of a Record from a File - K KarunDeletion of a Record from a File - K Karun
Deletion of a Record from a File - K Karun
 
Java Databse Connectvity- Alex Jose
Java Databse Connectvity- Alex JoseJava Databse Connectvity- Alex Jose
Java Databse Connectvity- Alex Jose
 
Computer Viruses- B S Kalyan Chakravarthy
Computer Viruses- B S Kalyan ChakravarthyComputer Viruses- B S Kalyan Chakravarthy
Computer Viruses- B S Kalyan Chakravarthy
 
Cloud Computing- Sreehari S
Cloud Computing- Sreehari SCloud Computing- Sreehari S
Cloud Computing- Sreehari S
 
SQL JOINS- Reena P V
SQL JOINS- Reena P VSQL JOINS- Reena P V
SQL JOINS- Reena P V
 

Recently uploaded

CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 

Recently uploaded (20)

CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 

File Handling - N K Upadhyay

  • 1. DATE:- 26/05/16 Presented By: Nitin Kumar Upadhyay K.V. Ramgarh Cantt Region:- Ranchi
  • 2. What is File and what is the purpose of using a File? A file can be defined as bunch of bytes stored on some storage media. Files are used to store data permanently in C++.
  • 3. What is Stream and how I/O Operations takes place in a file? A stream is a sequence of bytes or flow of data. Stream is needed to perform input and output operations in a file.
  • 4. What are different types of File Streams? There are two types of streams. ofstream :- It is used to write data to a file. Variable output stream File ifstream :- It is used to read data from a file. File input stream variable
  • 5. To learn Merge and Search operations first we have to understand file opening modes used for above said purpose. Q. What is file opening mode Ans. File opening Mode defines type of operations which we can perform with the file. For Merge and Search operation following modes are used. ios::out:- It creates a new file for writing. ios::in :- It opens an existing file for reading.
  • 6. Functions/Operators to read/write data from a file. Functions/Operators to read data from a file. <<, get( ), getline( ),read() Functions/Operators to write data to a file. >>,put( ),write( )
  • 7. Functions to read and write data from a file. S.No. Type of Data Function for Writing data to a file Function for Reading Data from a file 01 Number << >> 02 char put( ),<< get( ),>> 03 Word << >> 04 String << >> 05 Line/Sentence << get( ) getline( ) 06 Record read( ) write( )
  • 8. To perform search operation in file. It must be open in ios::in mode and the data must be read from file as per the type of data or requirement. For ex. (i)Suppose a question is given to count or perform any operation in file on the basis of alphabets like counting of vowels or blank spaces etc. Then data must be read from file using fstream.get(char_var); If stream object is f1 and char variable is ch then f1.get(ch);
  • 9. To perform search operation in file. (ii) If question is given to count no of words or occurrence of a particular word then Then data must be read from file using file_stream>>string_var; If stream object is f1 and string variable is str then f1 >> str;
  • 10. To perform search operation in file. (iii) if question is given to count no of lines present in a file. Then data must be read from file using file_stream.get(str,no_of_char,delim_char) If stream object is f1 and string variable is str then f1.get(str,80,’n’); or f1.getline(str,80,’n’);
  • 11. To perform search operation in file. (iv) if question is given to count no of records Then data must be read from file using file_stream.read((char *)&o,sizeof(o)); If stream object is f1 and structure variable/class object is o then f1.read((char *)&o,sizeof(o));
  • 12. To perform search operation in a file implemeted using structure. For example suppose stu is a structure with following definition and student.dat is a file which contains details of students as given structure. strcut stu { int rollno; char name[30]; float per; }s;
  • 13. then to search record of a student having name sumit. void search( ) { fstream f1;char str[40]; f1.open(“student.dat”,ios::in|ios::binary); while(!f1.eof( )) { f1.read((char *)&s,sizeof(s)); if(strcmp(s.name,”sumit”)==0) cout<<s.rollno<<s.percentage } f1.close( ); }
  • 14. To add one more record of a student. void append( ) { fstream f1;student p; f1.open(“student.dat”,ios::app|ios::binary); while(!f1.eof( )) { cout<<“Input rollno,name and percentage”; cin>>s.rollno;gets(s.name);cin>>s.per; f1.write((char *)&s,sizeof(s)); } f1.close( ); }
  • 15.  #include<fstream.h>  #include <conio.h>  #include<stdio.h>  void main( )  {  char ch;  char str[20];  fstream f1,f2,f3;  f1.open("abc1.txt",ios::out);  cout<<"input str";  gets(str);
  • 16.  f1<<str;  f1.close();  f2.open("abc2.txt",ios::out);  cout<<"input str";  gets(str);  f2<<str;  f2.close();  f1.open("abc1.txt",ios::in);  f2.open("abc2.txt",ios::in);  f3.open("abc3.txt",ios::app);
  • 17.  while(!f1.eof())  { f1.get(ch);  f3.put(ch);}  while(!f2.eof())  { f2.get(ch);  f3.put(ch); }  f1.close(); f2.close(); f3.close();  f3.open(“abc3.txt”,ios::in);  while(!f3.eof())  { f3>>(str);  cout<<str  }  f3.close();