Class 12 Data File Handling In C++ Revision Notes

Scroll down for PDF

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 on the text For more study material for Computer Science please click here - Computer Science

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

CBSE Board Exam Date Sheet of class 10th and 12th

The Central Board of Secondary Education (CBSE) released the Date sheet of Class 10 and Class 12th 2020 examination on the official website The board examination of Class 12 will be conducted from 15 February to 30 March 2020, while the board examination...

Simple tips to Excel in Examinations

We are entering the last quarter of the Academic Session. With examinations just around the corner, I am sure all of us are carrying a mixed bag of Stress, Excitement, and Anxieties!! So, first and foremost- Let’s be Positive and Futuristic! It’s most important to...

CBSE Counseling for Board exam 2020 starts today

The 23rd psychological Counseling starts 1st February (today) for The Class10 and Class12 CBSE students and their parents, by the Central Board of Secondary Education (CBSE).    This Counseling service is cost-free and this counseling service will be available every...

Studies Today