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 ()
All 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
file.open ("example.dat", ios::out | ios::app | ios::binary);
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.
For more study material for Computer Science please click here - Computer Science