SlideShare a Scribd company logo
File Handling
IN C++
What Is File?
A file is a collection on information, usually
stored on a computer's disk. Information
can be saved to files and then later reused.
Flow Of Data
The following classes in C++
have access to file input and
output functions:
 fstream
 Ifstream
 ofstream
DIFFERENT FILE OPERATIONS
 OPENING A FILE
 CLOSING A FILE
 READING FROM A FILE
 WRITING ON A FILE
 CHECKING FOR END OF FILE
OPENING A FILE
1.By using the CONSTRUCTOR of the stream class.
ifstream transaction(“xyz.txt");
ofstream result("result.02");
2.By using the open() function of the stream class
ifstream transaction;
transaction.open(“xyz.txt");
File Mode Parameters
MODES MEANINGS
 ios::app Append to end-of file
 ios::ate Goto end of file on opening
 ios::binary Binary file
 ios::in Open existing file for reading
 ios::nocreate Open fails if file doesn't exist
 ios::noreplace Open fails if file already exists
 ios::out Open existing file for writing
 ios::trunc Deletes contents if it exists
The mode can combine two or more modes using bit wise or (l)
Checking For Successful File Opening
ifstream transaction("sale.txt");
if (transcation == NULL)
{
cout<<"unable to open sales.dly";
cin.get(); //waits for the operator to press any key
exit(l);
}
Closing of File
Stream name.close();
e.g., transaction.close();
Types of Files
 The two basic types of files are
1.Text File
&
2.Binary File
Text File Binary File
 When using a text file, we
write out separately each of
the pieces of data about a
given record.
 The text file will be readable
by an editor.
 for the text file we will use
the usual output
operator(<<) and will output
each of the pieces of the
record separately.
 with the text file we will read
each of the pieces of record
from the file separately,
using the usual input
operator(>>)
 When using a Binary file we
write whole record data to
the file at once.
 But the numbers in the
binary file will not be
readable in this way.
 For the binary file we will use
write to write to the file.
 With the binary file we will
use the read function to read
a whole record.
Prepared By:-
Jay Panchal 12202040501030
Kirtan Soni 12202040501032

More Related Content

Similar to File Handling in c++

Filesinc 130512002619-phpapp01
Filesinc 130512002619-phpapp01Filesinc 130512002619-phpapp01
Filesinc 130512002619-phpapp01
Rex Joe
 
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
anuvayalil5525
 
Input File dalam C++
Input File dalam C++Input File dalam C++
Input File dalam C++
Teguh Nugraha
 

Similar to File Handling in c++ (20)

Basics of files and its functions with example
Basics of files and its functions with exampleBasics of files and its functions with example
Basics of files and its functions with example
 
File Handling In C++(OOPs))
File Handling In C++(OOPs))File Handling In C++(OOPs))
File Handling In C++(OOPs))
 
Chapter - 5.pptx
Chapter - 5.pptxChapter - 5.pptx
Chapter - 5.pptx
 
Data file handling
Data file handlingData file handling
Data file handling
 
File handling in_c
File handling in_cFile handling in_c
File handling in_c
 
File Handling in C++
File Handling in C++File Handling in C++
File Handling in C++
 
File Handling
File HandlingFile Handling
File Handling
 
File Handling
File HandlingFile Handling
File Handling
 
C++ Files and Streams
C++ Files and Streams C++ Files and Streams
C++ Files and Streams
 
7 Data File Handling
7 Data File Handling7 Data File Handling
7 Data File Handling
 
Filesinc 130512002619-phpapp01
Filesinc 130512002619-phpapp01Filesinc 130512002619-phpapp01
Filesinc 130512002619-phpapp01
 
Files in c++
Files in c++Files in c++
Files in c++
 
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
 
File Handling
File HandlingFile Handling
File Handling
 
Files and streams
Files and streamsFiles and streams
Files and streams
 
Data file handling
Data file handlingData file handling
Data file handling
 
Input File dalam C++
Input File dalam C++Input File dalam C++
Input File dalam C++
 
chapter-12-data-file-handling.pdf
chapter-12-data-file-handling.pdfchapter-12-data-file-handling.pdf
chapter-12-data-file-handling.pdf
 
Chapter10
Chapter10Chapter10
Chapter10
 
File handling
File handlingFile handling
File handling
 

Recently uploaded

CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
R&R Consult
 
LIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.pptLIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.ppt
ssuser9bd3ba
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
Neometrix_Engineering_Pvt_Ltd
 

Recently uploaded (20)

The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
 
Cloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptx
Cloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptxCloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptx
Cloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptx
 
Halogenation process of chemical process industries
Halogenation process of chemical process industriesHalogenation process of chemical process industries
Halogenation process of chemical process industries
 
A CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdf
A CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdfA CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdf
A CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdf
 
LIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.pptLIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.ppt
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
 
Democratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek AryaDemocratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek Arya
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
 
A case study of cinema management system project report..pdf
A case study of cinema management system project report..pdfA case study of cinema management system project report..pdf
A case study of cinema management system project report..pdf
 
İTÜ CAD and Reverse Engineering Workshop
İTÜ CAD and Reverse Engineering WorkshopİTÜ CAD and Reverse Engineering Workshop
İTÜ CAD and Reverse Engineering Workshop
 
fundamentals of drawing and isometric and orthographic projection
fundamentals of drawing and isometric and orthographic projectionfundamentals of drawing and isometric and orthographic projection
fundamentals of drawing and isometric and orthographic projection
 
shape functions of 1D and 2 D rectangular elements.pptx
shape functions of 1D and 2 D rectangular elements.pptxshape functions of 1D and 2 D rectangular elements.pptx
shape functions of 1D and 2 D rectangular elements.pptx
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
 
Toll tax management system project report..pdf
Toll tax management system project report..pdfToll tax management system project report..pdf
Toll tax management system project report..pdf
 

File Handling in c++

  • 2. What Is File? A file is a collection on information, usually stored on a computer's disk. Information can be saved to files and then later reused.
  • 4. The following classes in C++ have access to file input and output functions:  fstream  Ifstream  ofstream
  • 5.
  • 6. DIFFERENT FILE OPERATIONS  OPENING A FILE  CLOSING A FILE  READING FROM A FILE  WRITING ON A FILE  CHECKING FOR END OF FILE
  • 7. OPENING A FILE 1.By using the CONSTRUCTOR of the stream class. ifstream transaction(“xyz.txt"); ofstream result("result.02"); 2.By using the open() function of the stream class ifstream transaction; transaction.open(“xyz.txt");
  • 8. File Mode Parameters MODES MEANINGS  ios::app Append to end-of file  ios::ate Goto end of file on opening  ios::binary Binary file  ios::in Open existing file for reading  ios::nocreate Open fails if file doesn't exist  ios::noreplace Open fails if file already exists  ios::out Open existing file for writing  ios::trunc Deletes contents if it exists The mode can combine two or more modes using bit wise or (l)
  • 9. Checking For Successful File Opening ifstream transaction("sale.txt"); if (transcation == NULL) { cout<<"unable to open sales.dly"; cin.get(); //waits for the operator to press any key exit(l); }
  • 10. Closing of File Stream name.close(); e.g., transaction.close();
  • 11. Types of Files  The two basic types of files are 1.Text File & 2.Binary File
  • 12. Text File Binary File  When using a text file, we write out separately each of the pieces of data about a given record.  The text file will be readable by an editor.  for the text file we will use the usual output operator(<<) and will output each of the pieces of the record separately.  with the text file we will read each of the pieces of record from the file separately, using the usual input operator(>>)  When using a Binary file we write whole record data to the file at once.  But the numbers in the binary file will not be readable in this way.  For the binary file we will use write to write to the file.  With the binary file we will use the read function to read a whole record.
  • 13. Prepared By:- Jay Panchal 12202040501030 Kirtan Soni 12202040501032