SlideShare a Scribd company logo
SUBJECT :- Object Oriented Programming with C++
TOPIC :- File Management Functions
Prepared by: Vaani Pathak
Branch: CE
Division: B3
Enrollment No.: 170120107131
Guided by: Utsav Shah
Introduction
Gandhinagar Institute Of Technology2
 In Files we store data i.e. text or binary data
permanently and use these data to read or write in
the form of input output operations by transferring
bytes of data.
 So we use the term File Streams/File handling.
 We use the header file <fstream>
Header file
Gandhinagar Institute Of Technology3
 ofstream: It represents output Stream and this is
used for writing in files.
 ifstream: It represents input Stream and this is used
for reading from files.
 fstream: It represents both output Stream and input
Stream. So it can read from files and write to files.
Operations in File Management
Gandhinagar Institute Of Technology 4
 Below the operations used for file management in
c++
o Creating a file: open()
o Reading data: read()
o Writing new data: write()
o Closing a file: close()
Creating/Opening a File
Gandhinagar Institute Of Technology5
 A file must be opened before you can read from it or
write
 Here, the first argument specifies the name and
location of the file to be opened and the second
argument of the open() member function defines the
mode in which the file should be opened.
o void open(const char *filename, ios::openmode mode);
Types:
Gandhinagar Institute Of Technology6
File opened for writing ios::out
File opened for reading ios::in
File opened for appending ios::app
File opened for truncating ios::trunc
Reading from a File
Gandhinagar Institute Of Technology7
 You read information from a file into your program
using the stream extraction operator (>>) just as you
use that operator to input information from the
keyboard.
 The only difference is that you use
an ifstream or fstream object instead of
the cin object.
Writing to a File
Gandhinagar Institute Of Technology8
 While doing C++ programming, you write information
to a file from your program using the stream insertion
operator (<<) just as you use that operator to output
information to the screen.
 The only difference is that you use
an ofstream or fstream object instead of
the cout object.
Closing a File
Gandhinagar Institute Of Technology9
 When a C++ program terminates it automatically
flushes all the streams, release all the allocated
memory and close all the opened files.
 But it is always a good practice that a programmer
should close all the opened files before program
termination.
 Following is the standard syntax for close() function,
which is a member of fstream, ifstream, and
ofstream objects.
THANK YOU

More Related Content

Similar to file management functions

C++ Files and Streams
C++ Files and Streams C++ Files and Streams
C++ Files and Streams
Ahmed Farag
 
Stream classes in C++
Stream classes in C++Stream classes in C++
Stream classes in C++
Shyam Gupta
 
Basics of file handling
Basics of file handlingBasics of file handling
Basics of file handling
pinkpreet_kaur
 
basics of file handling
basics of file handlingbasics of file handling
basics of file handling
pinkpreet_kaur
 
Chapter4.pptx
Chapter4.pptxChapter4.pptx
Chapter4.pptx
WondimuBantihun1
 
new pdfrdfzdfzdzzzzzzzzzzzzzzzzzzzzzzzzzzgggggggggggggggggggggggggggggggggggg...
new pdfrdfzdfzdzzzzzzzzzzzzzzzzzzzzzzzzzzgggggggggggggggggggggggggggggggggggg...new pdfrdfzdfzdzzzzzzzzzzzzzzzzzzzzzzzzzzgggggggggggggggggggggggggggggggggggg...
new pdfrdfzdfzdzzzzzzzzzzzzzzzzzzzzzzzzzzgggggggggggggggggggggggggggggggggggg...
AzanMehdi
 
File handling in cpp
File handling in cppFile handling in cpp
File handling
File handlingFile handling
File handling
muhammad sharif bugti
 
File management in C++
File management in C++File management in C++
File management in C++
apoorvaverma33
 
Streams and Files
Streams and FilesStreams and Files
Streams and Files
Munazza-Mah-Jabeen
 
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
Sunil Patel
 
File in cpp 2016
File in cpp 2016 File in cpp 2016
File in cpp 2016
Dr .Ahmed Tawwab
 
chapter-12-data-file-handling.pdf
chapter-12-data-file-handling.pdfchapter-12-data-file-handling.pdf
chapter-12-data-file-handling.pdf
study material
 
File Handling
File HandlingFile Handling
File Handling
AlgeronTongdoTopi
 
File Handling
File HandlingFile Handling
File Handling
AlgeronTongdoTopi
 
File handling in_c
File handling in_cFile handling in_c
File handling in_c
sanya6900
 
Data file handling
Data file handlingData file handling
Data file handling
Prof. Dr. K. Adisesha
 
Files in c++ ppt
Files in c++ pptFiles in c++ ppt
Files in c++ ppt
Kumar
 
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)
Abdullah khawar
 
7 Data File Handling
7 Data File Handling7 Data File Handling
7 Data File Handling
Praveen M Jigajinni
 

Similar to file management functions (20)

C++ Files and Streams
C++ Files and Streams C++ Files and Streams
C++ Files and Streams
 
Stream classes in C++
Stream classes in C++Stream classes in C++
Stream classes in C++
 
Basics of file handling
Basics of file handlingBasics of file handling
Basics of file handling
 
basics of file handling
basics of file handlingbasics of file handling
basics of file handling
 
Chapter4.pptx
Chapter4.pptxChapter4.pptx
Chapter4.pptx
 
new pdfrdfzdfzdzzzzzzzzzzzzzzzzzzzzzzzzzzgggggggggggggggggggggggggggggggggggg...
new pdfrdfzdfzdzzzzzzzzzzzzzzzzzzzzzzzzzzgggggggggggggggggggggggggggggggggggg...new pdfrdfzdfzdzzzzzzzzzzzzzzzzzzzzzzzzzzgggggggggggggggggggggggggggggggggggg...
new pdfrdfzdfzdzzzzzzzzzzzzzzzzzzzzzzzzzzgggggggggggggggggggggggggggggggggggg...
 
File handling in cpp
File handling in cppFile handling in cpp
File handling in cpp
 
File handling
File handlingFile handling
File handling
 
File management in C++
File management in C++File management in C++
File management in C++
 
Streams and Files
Streams and FilesStreams and Files
Streams and Files
 
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 in cpp 2016
File in cpp 2016 File in cpp 2016
File in cpp 2016
 
chapter-12-data-file-handling.pdf
chapter-12-data-file-handling.pdfchapter-12-data-file-handling.pdf
chapter-12-data-file-handling.pdf
 
File Handling
File HandlingFile Handling
File Handling
 
File Handling
File HandlingFile Handling
File Handling
 
File handling in_c
File handling in_cFile handling in_c
File handling in_c
 
Data file handling
Data file handlingData file handling
Data file handling
 
Files in c++ ppt
Files in c++ pptFiles in c++ ppt
Files in c++ ppt
 
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)
 
7 Data File Handling
7 Data File Handling7 Data File Handling
7 Data File Handling
 

More from vaani pathak

D’Alembert’s Solution of the Wave Equation
D’Alembert’s Solution of the Wave EquationD’Alembert’s Solution of the Wave Equation
D’Alembert’s Solution of the Wave Equation
vaani pathak
 
Dynamic Memory Allocation
Dynamic Memory AllocationDynamic Memory Allocation
Dynamic Memory Allocation
vaani pathak
 
error detection
error detectionerror detection
error detection
vaani pathak
 
interpolation of unequal intervals
interpolation of unequal intervalsinterpolation of unequal intervals
interpolation of unequal intervals
vaani pathak
 
Arc Length, Curvature and Torsion
Arc Length, Curvature and TorsionArc Length, Curvature and Torsion
Arc Length, Curvature and Torsion
vaani pathak
 
Cpd 4.2
Cpd 4.2Cpd 4.2
Cpd 4.2
vaani pathak
 
CPD ch 7
CPD ch 7CPD ch 7
CPD ch 7
vaani pathak
 
Chain Drive
Chain DriveChain Drive
Chain Drive
vaani pathak
 
AM FM PM
AM FM PMAM FM PM
AM FM PM
vaani pathak
 
Fixtures and Reflectors
Fixtures and ReflectorsFixtures and Reflectors
Fixtures and Reflectors
vaani pathak
 
Calculus ppt format
Calculus ppt formatCalculus ppt format
Calculus ppt format
vaani pathak
 
Planning for presentation
Planning for presentationPlanning for presentation
Planning for presentation
vaani pathak
 
Types of polarisation
Types of polarisationTypes of polarisation
Types of polarisation
vaani pathak
 
CPU Algorithm
CPU Algorithm CPU Algorithm
CPU Algorithm
vaani pathak
 
Air Pollution Acts
Air Pollution ActsAir Pollution Acts
Air Pollution Acts
vaani pathak
 

More from vaani pathak (15)

D’Alembert’s Solution of the Wave Equation
D’Alembert’s Solution of the Wave EquationD’Alembert’s Solution of the Wave Equation
D’Alembert’s Solution of the Wave Equation
 
Dynamic Memory Allocation
Dynamic Memory AllocationDynamic Memory Allocation
Dynamic Memory Allocation
 
error detection
error detectionerror detection
error detection
 
interpolation of unequal intervals
interpolation of unequal intervalsinterpolation of unequal intervals
interpolation of unequal intervals
 
Arc Length, Curvature and Torsion
Arc Length, Curvature and TorsionArc Length, Curvature and Torsion
Arc Length, Curvature and Torsion
 
Cpd 4.2
Cpd 4.2Cpd 4.2
Cpd 4.2
 
CPD ch 7
CPD ch 7CPD ch 7
CPD ch 7
 
Chain Drive
Chain DriveChain Drive
Chain Drive
 
AM FM PM
AM FM PMAM FM PM
AM FM PM
 
Fixtures and Reflectors
Fixtures and ReflectorsFixtures and Reflectors
Fixtures and Reflectors
 
Calculus ppt format
Calculus ppt formatCalculus ppt format
Calculus ppt format
 
Planning for presentation
Planning for presentationPlanning for presentation
Planning for presentation
 
Types of polarisation
Types of polarisationTypes of polarisation
Types of polarisation
 
CPU Algorithm
CPU Algorithm CPU Algorithm
CPU Algorithm
 
Air Pollution Acts
Air Pollution ActsAir Pollution Acts
Air Pollution Acts
 

Recently uploaded

Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
IJECEIAES
 
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
Paris Salesforce Developer Group
 
SCALING OF MOS CIRCUITS m .pptx
SCALING OF MOS CIRCUITS m                 .pptxSCALING OF MOS CIRCUITS m                 .pptx
SCALING OF MOS CIRCUITS m .pptx
harshapolam10
 
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by AnantLLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
Anant Corporation
 
AI for Legal Research with applications, tools
AI for Legal Research with applications, toolsAI for Legal Research with applications, tools
AI for Legal Research with applications, tools
mahaffeycheryld
 
ITSM Integration with MuleSoft.pptx
ITSM  Integration with MuleSoft.pptxITSM  Integration with MuleSoft.pptx
ITSM Integration with MuleSoft.pptx
VANDANAMOHANGOUDA
 
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
upoux
 
An Introduction to the Compiler Designss
An Introduction to the Compiler DesignssAn Introduction to the Compiler Designss
An Introduction to the Compiler Designss
ElakkiaU
 
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
IJECEIAES
 
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
IJECEIAES
 
Welding Metallurgy Ferrous Materials.pdf
Welding Metallurgy Ferrous Materials.pdfWelding Metallurgy Ferrous Materials.pdf
Welding Metallurgy Ferrous Materials.pdf
AjmalKhan50578
 
Curve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods RegressionCurve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods Regression
Nada Hikmah
 
Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...
Prakhyath Rai
 
Digital Twins Computer Networking Paper Presentation.pptx
Digital Twins Computer Networking Paper Presentation.pptxDigital Twins Computer Networking Paper Presentation.pptx
Digital Twins Computer Networking Paper Presentation.pptx
aryanpankaj78
 
Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...
bijceesjournal
 
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
ecqow
 
Design and optimization of ion propulsion drone
Design and optimization of ion propulsion droneDesign and optimization of ion propulsion drone
Design and optimization of ion propulsion drone
bjmsejournal
 
VARIABLE FREQUENCY DRIVE. VFDs are widely used in industrial applications for...
VARIABLE FREQUENCY DRIVE. VFDs are widely used in industrial applications for...VARIABLE FREQUENCY DRIVE. VFDs are widely used in industrial applications for...
VARIABLE FREQUENCY DRIVE. VFDs are widely used in industrial applications for...
PIMR BHOPAL
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
VICTOR MAESTRE RAMIREZ
 
TIME TABLE MANAGEMENT SYSTEM testing.pptx
TIME TABLE MANAGEMENT SYSTEM testing.pptxTIME TABLE MANAGEMENT SYSTEM testing.pptx
TIME TABLE MANAGEMENT SYSTEM testing.pptx
CVCSOfficial
 

Recently uploaded (20)

Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
 
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
 
SCALING OF MOS CIRCUITS m .pptx
SCALING OF MOS CIRCUITS m                 .pptxSCALING OF MOS CIRCUITS m                 .pptx
SCALING OF MOS CIRCUITS m .pptx
 
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by AnantLLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
 
AI for Legal Research with applications, tools
AI for Legal Research with applications, toolsAI for Legal Research with applications, tools
AI for Legal Research with applications, tools
 
ITSM Integration with MuleSoft.pptx
ITSM  Integration with MuleSoft.pptxITSM  Integration with MuleSoft.pptx
ITSM Integration with MuleSoft.pptx
 
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
 
An Introduction to the Compiler Designss
An Introduction to the Compiler DesignssAn Introduction to the Compiler Designss
An Introduction to the Compiler Designss
 
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
 
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
 
Welding Metallurgy Ferrous Materials.pdf
Welding Metallurgy Ferrous Materials.pdfWelding Metallurgy Ferrous Materials.pdf
Welding Metallurgy Ferrous Materials.pdf
 
Curve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods RegressionCurve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods Regression
 
Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...
 
Digital Twins Computer Networking Paper Presentation.pptx
Digital Twins Computer Networking Paper Presentation.pptxDigital Twins Computer Networking Paper Presentation.pptx
Digital Twins Computer Networking Paper Presentation.pptx
 
Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...
 
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
 
Design and optimization of ion propulsion drone
Design and optimization of ion propulsion droneDesign and optimization of ion propulsion drone
Design and optimization of ion propulsion drone
 
VARIABLE FREQUENCY DRIVE. VFDs are widely used in industrial applications for...
VARIABLE FREQUENCY DRIVE. VFDs are widely used in industrial applications for...VARIABLE FREQUENCY DRIVE. VFDs are widely used in industrial applications for...
VARIABLE FREQUENCY DRIVE. VFDs are widely used in industrial applications for...
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
 
TIME TABLE MANAGEMENT SYSTEM testing.pptx
TIME TABLE MANAGEMENT SYSTEM testing.pptxTIME TABLE MANAGEMENT SYSTEM testing.pptx
TIME TABLE MANAGEMENT SYSTEM testing.pptx
 

file management functions

  • 1. SUBJECT :- Object Oriented Programming with C++ TOPIC :- File Management Functions Prepared by: Vaani Pathak Branch: CE Division: B3 Enrollment No.: 170120107131 Guided by: Utsav Shah
  • 2. Introduction Gandhinagar Institute Of Technology2  In Files we store data i.e. text or binary data permanently and use these data to read or write in the form of input output operations by transferring bytes of data.  So we use the term File Streams/File handling.  We use the header file <fstream>
  • 3. Header file Gandhinagar Institute Of Technology3  ofstream: It represents output Stream and this is used for writing in files.  ifstream: It represents input Stream and this is used for reading from files.  fstream: It represents both output Stream and input Stream. So it can read from files and write to files.
  • 4. Operations in File Management Gandhinagar Institute Of Technology 4  Below the operations used for file management in c++ o Creating a file: open() o Reading data: read() o Writing new data: write() o Closing a file: close()
  • 5. Creating/Opening a File Gandhinagar Institute Of Technology5  A file must be opened before you can read from it or write  Here, the first argument specifies the name and location of the file to be opened and the second argument of the open() member function defines the mode in which the file should be opened. o void open(const char *filename, ios::openmode mode);
  • 6. Types: Gandhinagar Institute Of Technology6 File opened for writing ios::out File opened for reading ios::in File opened for appending ios::app File opened for truncating ios::trunc
  • 7. Reading from a File Gandhinagar Institute Of Technology7  You read information from a file into your program using the stream extraction operator (>>) just as you use that operator to input information from the keyboard.  The only difference is that you use an ifstream or fstream object instead of the cin object.
  • 8. Writing to a File Gandhinagar Institute Of Technology8  While doing C++ programming, you write information to a file from your program using the stream insertion operator (<<) just as you use that operator to output information to the screen.  The only difference is that you use an ofstream or fstream object instead of the cout object.
  • 9. Closing a File Gandhinagar Institute Of Technology9  When a C++ program terminates it automatically flushes all the streams, release all the allocated memory and close all the opened files.  But it is always a good practice that a programmer should close all the opened files before program termination.  Following is the standard syntax for close() function, which is a member of fstream, ifstream, and ofstream objects.