Class 12 Data File Handling In C++ Revision Notes

File: - The information / data stored under a specific name on a storage device, is called a file.
Stream: - It refers to a sequence of bytes.
Text file: - It is a file that stores information in ASCII characters. In text files, each line of text is terminated with a special character known as EOL (End of Line) character or delimiter character.
When this EOL character is read or written, certain internal translations take place.
Binary file:- It is a file that contains information in the same format as it is held in memory. In binary files, no delimiters are used for a line and no translations occur here.
Classes used for different file related operation
ofstream: Object of ofstream class used to write data to the files.
ifstream: Object of ifstream class used to read from files
fstream: Object of fstream class used to both read and write from/to files.
Opening a file

Opening file using constructor
ofstream outFile("sample.txt");      //output only
ifstream inFile(“sample.txt”);        //input only
Opening File Using open ()“filename”, [mode]);
ofstream outFile;"sample.txt");
ifstream inFile;"sample.txt");
Class 12 Data File Handling In C++ Revision NotesAll these flags can be combined using the bitwise operator OR (|). For example, if we want to open the file example.dat in binary mode to add data we could do it by the following call to member
function open():
fstream file; ("example.dat", ios::out | ios::app | ios::binary);
Closing File
Input and output operation

put() and get() function
the function put() writes a single character to the associated stream. Similarly, the function get()
reads a single character form the associated stream.
example :


Click to View or Download pdf file
Click for more Computer Science Study Material

Latest NCERT & CBSE News

Read the latest news and announcements from NCERT and CBSE below. Important updates relating to your studies which will help you to keep yourself updated with latest happenings in school level education. Keep yourself updated with all latest news and also read articles from teachers which will help you to improve your studies, increase motivation level and promote faster learning

Online Teacher Training Course on Competency based Education in DIKSHA

Competency is a set of skills, abilities, knowledge that helps an individual perform a given task in real life. Every learning should go into the imbibing of these skills to lead a productive and joyful life. The NATIONAL EDUCATION POLICY-2020 calls for shift towards...

TERI Green Olympiad 2020

Green Olympiad is a value driven project conducted by TERI (The Energy and Resources Institute) for school students annually since 1999. This Olympiad assesses the environment quotient of students and also enhances their understanding on issues related to sustainable...

Revised SOP preventive measures followed while conducting examinations

Revised SOP on preventive measures to be followed while conducting examinations to contain spread of COVID-19 issued by Ministry of Health & Family Welfare Examination centres are frequented by large number of students (as well as their parents) and staff till the...

NEP Transforming India Quiz

As a part of Shikshak Parv celebration, an online quiz competition on National Education Policy 2020 will be organized by the Ministry of Education, Govt. of India, from 5 th September to 25th September 2020 in order to create awareness about NEP among all stakeholders...

National Online Painting Championship

The National Mission for Clean Ganga, Ministry of Jal Shakti in collaboration with Kalantar Art Trust is organizing KALANTAR-2020: National Online Painting Championship with the aim to provide a platform to youth and school children to demonstrate their artistic skills...

Training of CBSE School Teachers on Olabs

Training of CBSE School Teachers on Olabs in collaboration with C-DAC Mumbai: OLabs is a platform jointly developed by the Ministry of Electronics and Telecommunications, Government of India, CDAC, and Amrita University to facilitate a virtual experience of CBSE...

Studies Today