SlideShare a Scribd company logo
Files
• File is a collection of related records.
• Permanent Storage
• User Input -> Variables -> Program -> File
• File -> Data Read to Program
• Types of Files
• Text Files (readable & printable characters)
• Binary Files (non-readable binary code)
File Access Methods
• Sequential Access Method
• Have to read all record in order to read a later
byte
• Slow Method
• Variable Length Records, Memory is not wasted
• Random Access Method
• Direct access
• Faster Method
• Fixed Length Records, Memory wasted
Stream
• A stream is a series of bytes associated with a
file.
• Exchange of data between program and file in
the form of bytes.
• Types of Streams
• Standard Input Stream
• Connection between standard input device and program
• Act of reading data from an input stream is called
Extraction.
• Uses >> operator. E.g. cin object, part of istream
• Standard Output Stream
• Connection between standard output device and program.
• Act of writing data to an output stream is called Insertion.
Predefined Stream Objects
• cin -> File -> istream
• cout -> File -> ostream
• cerr -> Monitor -> ostream
• clog -> Monitor -> ostream
• These objects can be redirected to other
devices or files.
Stream Class Hierarchy
ios
istream ostream
ifstream iostream ofstream
fstream
Opening Files
• File Pointer
• Ifstream, ofstream, fstream
• open() function
• File Opening Modes
• ios::in input mode
• ios::out output mode
• ios:binary binary mode
• ios:ate sets file pointer at the end of the file,
input/output mode
• ios::app append, only used in output mode
• ios::trunc deletes previous data (if any) of the file
• ios::nocreate opens file only if it exists
• ios::noreplace opens file only if it does not exist
• Multiple modes can also be specified using | symbol.
Default File Opening Modes
• ios::in for ifstream file pointer
• ios::out for ofstream file pointer
• ios::in | ios::out for fstream file
pointer
Verifying File Opening
• is_open() function
• !fp
Closing Files
• close() function
Formatted Files I/O
• Series of characters
• Each character takes one byte
• 38.125 will take 6 bytes.
• Not storage efficient
• Easy to implement
• End of File Detection eof() function
Character File I/O
• Only one character at a time
• put() function
• get() function
Binary File I/O
• Efficient data storage
• write() function
• read() function

More Related Content

Similar to File Handling in CPP Programming Language.pptx (20)

PPTX
Chapter4.pptx
WondimuBantihun1
 
PPT
FILE HANDLING IN C++. +2 COMPUTER SCIENCE CBSE AND STATE SYLLABUS
Venugopalavarma Raja
 
PDF
Basics of files and its functions with example
Sunil Patel
 
PDF
Files and streams
Pranali Chaudhari
 
PPSX
Files in c++
Selvin Josy Bai Somu
 
PDF
Filesinc 130512002619-phpapp01
Rex Joe
 
PPTX
File Handling
TusharBatra27
 
PPTX
Filesin c++
HalaiHansaika
 
PPTX
Files in c++
NivethaJeyaraman
 
PPT
Filehandlinging cp2
Tanmay Baranwal
 
PDF
Data file handling
Prof. Dr. K. Adisesha
 
PDF
Files in C++.pdf is the notes of cpp for reference
anuvayalil5525
 
PDF
8. file handling
Lahore Garrison University
 
PPTX
File management in C++
apoorvaverma33
 
PDF
file handling c++
Guddu Spy
 
PPTX
Data file handling in c++
Vineeta Garg
 
PPTX
File handling
Amber Wajid
 
PDF
Chapter28 data-file-handling
Deepak Singh
 
Chapter4.pptx
WondimuBantihun1
 
FILE HANDLING IN C++. +2 COMPUTER SCIENCE CBSE AND STATE SYLLABUS
Venugopalavarma Raja
 
Basics of files and its functions with example
Sunil Patel
 
Files and streams
Pranali Chaudhari
 
Files in c++
Selvin Josy Bai Somu
 
Filesinc 130512002619-phpapp01
Rex Joe
 
File Handling
TusharBatra27
 
Filesin c++
HalaiHansaika
 
Files in c++
NivethaJeyaraman
 
Filehandlinging cp2
Tanmay Baranwal
 
Data file handling
Prof. Dr. K. Adisesha
 
Files in C++.pdf is the notes of cpp for reference
anuvayalil5525
 
8. file handling
Lahore Garrison University
 
File management in C++
apoorvaverma33
 
file handling c++
Guddu Spy
 
Data file handling in c++
Vineeta Garg
 
File handling
Amber Wajid
 
Chapter28 data-file-handling
Deepak Singh
 

Recently uploaded (20)

PPTX
Nutri-QUIZ-Bee-Elementary.pptx...................
ferdinandsanbuenaven
 
PDF
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
PDF
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
PPTX
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
PDF
The-Beginnings-of-Indian-Civilisation.pdf/6th class new ncert social/by k san...
Sandeep Swamy
 
PDF
IMP NAAC REFORMS 2024 - 10 Attributes.pdf
BHARTIWADEKAR
 
PPTX
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
PPTX
Views on Education of Indian Thinkers Mahatma Gandhi.pptx
ShrutiMahanta1
 
PPTX
PPT on the Development of Education in the Victorian England
Beena E S
 
PPTX
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
PDF
CEREBRAL PALSY: NURSING MANAGEMENT .pdf
PRADEEP ABOTHU
 
PPTX
Accounting Skills Paper-I, Preparation of Vouchers
Dr. Sushil Bansode
 
PPT
digestive system for Pharm d I year HAP
rekhapositivity
 
PPTX
Explorando Recursos do Summer '25: Dicas Essenciais - 02
Mauricio Alexandre Silva
 
PPTX
HEAD INJURY IN CHILDREN: NURSING MANAGEMENGT.pptx
PRADEEP ABOTHU
 
PPTX
ROLE OF ANTIOXIDANT IN EYE HEALTH MANAGEMENT.pptx
Subham Panja
 
PPTX
Views on Education of Indian Thinkers J.Krishnamurthy..pptx
ShrutiMahanta1
 
PPTX
How to Manage Access Rights & User Types in Odoo 18
Celine George
 
PPSX
Health Planning in india - Unit 03 - CHN 2 - GNM 3RD YEAR.ppsx
Priyanshu Anand
 
PDF
Federal dollars withheld by district, charter, grant recipient
Mebane Rash
 
Nutri-QUIZ-Bee-Elementary.pptx...................
ferdinandsanbuenaven
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
The-Beginnings-of-Indian-Civilisation.pdf/6th class new ncert social/by k san...
Sandeep Swamy
 
IMP NAAC REFORMS 2024 - 10 Attributes.pdf
BHARTIWADEKAR
 
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
Views on Education of Indian Thinkers Mahatma Gandhi.pptx
ShrutiMahanta1
 
PPT on the Development of Education in the Victorian England
Beena E S
 
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
CEREBRAL PALSY: NURSING MANAGEMENT .pdf
PRADEEP ABOTHU
 
Accounting Skills Paper-I, Preparation of Vouchers
Dr. Sushil Bansode
 
digestive system for Pharm d I year HAP
rekhapositivity
 
Explorando Recursos do Summer '25: Dicas Essenciais - 02
Mauricio Alexandre Silva
 
HEAD INJURY IN CHILDREN: NURSING MANAGEMENGT.pptx
PRADEEP ABOTHU
 
ROLE OF ANTIOXIDANT IN EYE HEALTH MANAGEMENT.pptx
Subham Panja
 
Views on Education of Indian Thinkers J.Krishnamurthy..pptx
ShrutiMahanta1
 
How to Manage Access Rights & User Types in Odoo 18
Celine George
 
Health Planning in india - Unit 03 - CHN 2 - GNM 3RD YEAR.ppsx
Priyanshu Anand
 
Federal dollars withheld by district, charter, grant recipient
Mebane Rash
 
Ad

File Handling in CPP Programming Language.pptx

  • 1. Files • File is a collection of related records. • Permanent Storage • User Input -> Variables -> Program -> File • File -> Data Read to Program • Types of Files • Text Files (readable & printable characters) • Binary Files (non-readable binary code)
  • 2. File Access Methods • Sequential Access Method • Have to read all record in order to read a later byte • Slow Method • Variable Length Records, Memory is not wasted • Random Access Method • Direct access • Faster Method • Fixed Length Records, Memory wasted
  • 3. Stream • A stream is a series of bytes associated with a file. • Exchange of data between program and file in the form of bytes. • Types of Streams • Standard Input Stream • Connection between standard input device and program • Act of reading data from an input stream is called Extraction. • Uses >> operator. E.g. cin object, part of istream • Standard Output Stream • Connection between standard output device and program. • Act of writing data to an output stream is called Insertion.
  • 4. Predefined Stream Objects • cin -> File -> istream • cout -> File -> ostream • cerr -> Monitor -> ostream • clog -> Monitor -> ostream • These objects can be redirected to other devices or files.
  • 5. Stream Class Hierarchy ios istream ostream ifstream iostream ofstream fstream
  • 6. Opening Files • File Pointer • Ifstream, ofstream, fstream • open() function • File Opening Modes • ios::in input mode • ios::out output mode • ios:binary binary mode • ios:ate sets file pointer at the end of the file, input/output mode • ios::app append, only used in output mode • ios::trunc deletes previous data (if any) of the file • ios::nocreate opens file only if it exists • ios::noreplace opens file only if it does not exist • Multiple modes can also be specified using | symbol.
  • 7. Default File Opening Modes • ios::in for ifstream file pointer • ios::out for ofstream file pointer • ios::in | ios::out for fstream file pointer
  • 8. Verifying File Opening • is_open() function • !fp
  • 10. Formatted Files I/O • Series of characters • Each character takes one byte • 38.125 will take 6 bytes. • Not storage efficient • Easy to implement • End of File Detection eof() function
  • 11. Character File I/O • Only one character at a time • put() function • get() function
  • 12. Binary File I/O • Efficient data storage • write() function • read() function