by Dinesh Thakur Category: Array Pointer and Union

We know that Files are used for Storing Permanent information. And C++ provides a Facility to a developer the Retrieve the Information from File and he may also modify the Contents of a File So that we can say that File Handling is the Concept to Store, Retrieve and Modify the Information which is stored in the Form of Files in your Computer.

There are Many Built in Classes of C++ , Which Provides Various Functionality for Performing the Operations on Files . A user has a Ability to Modify the data of a File With the help of these Functions. Generally a user can use a File Read, Write or For Appending More data into the File so that C++ Provides Various Classes For Performing these Operations.  There are two most important Classes which are known as ifstream and ofstream. Ifstream stands for input Stream which is used for Reading the Contents from a File and output Stream or Simply ofstream is used for writing data into the Files.

       There is one More Class Which is used for Both Performing read and write known as fstream class and Always Remember for using Any Class First we have to use or include a header file which is called as Fstream.h header file.


Various Functions for Reading and writing data of Files

 
1)   get: - This Functions Stands for Reading data from a File in the Form of Character .

2)   Put :- This Function is used for Writing the data into a File in the Form of Characters

3)      <<  and >> These Operators are also used for Writing the data into the File , The Data may int,float or any other data type  . << Operator is used for Writing data into a File and >> Operator is used for Reading data from a File.  

4) Read and Write: - With the help of C++ one can also Read or Write the Data from a File . But C++ also Provides a Write Method or Function For Writing the data of A Class into a File Like Data of a Member Functions, Values of data Members of a Class and One Can also Read the Information once this written into a File with the help of Read Method or Function.

But Always Remember for reading or Writing data from a Class , first a user have to Explicitly Cast or  Convert  the data of a class in the form of characters because data is written into a File in the Form of Characters and a user have to create some Memory for Specifying how mush data is to be Written into a file and vive-versa for Reading data of a class from a File Whenever a user open a File, The File will Opened and the Pointer of File is stood on first Character or First Line of a File and if a user wants to Read all the data from a File then a user have to use eof () or Simply End of File Functions , a user can read the data until a File doesn’t comes to end A user have also a ability to read data from any Location from a File So that a User have to use Seekg function for Reading data from a Random Position With the help of Seekg function a user can read data from a file , from any position



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Related Articles