File handling is the process of storing the data permanently which gets generated during the execution of the program. The data once stored can be displayed later as per user requirement, the stored data can be modified and if the stored data is no longer required then it can be permanently deleted from the database.
A stream is a sequence of bytes.
A stream is a general name given to the flow of data. Different streams are used to represent different kinds of data flow. Each stream is associated with a particular class. This contains member functions and definitions for dealing with that particular kind of data flow.
the stream that supplies the data to the program is known as input stream. It reads the data from the file and hands it over to the program.
the stream that receives data from the program is known as an output stream.
Header file : fstream.h
Files are required to store the data permanently for later use. The data files are the files that store the data related to a particular application. The data files can be stored in two ways
* Text files
* Binary files
A text file stores information in ASCII characters. In text file, each line of text is terminated with a special character known as EOL (end of line) character. In text files some internal translation take place when this EOL character is read or written.
A binary file is just a file that contains information in the same format in which the information is held in the memory. In binary file, there is no delimiter for a line. Also no translation occurs in binary file. As a result the binary files are faster and easier for a program to read and write than are the text files. As long as the files doesn’t need to be read by people or need to be ported to a different type system, binary files are the best way to store the program.
Note: When we work in files in C++, unless we specify, files are default considered as and treated as text files.