
Finding End of a File 653
16.5 FINDING END OF A FILE
While reading data from a file, it is necessary to find where the file ends, that is, the end of the
file. The programmer cannot predict the end of the file. If in a program, while reading the file,
the program does not detect the end of the file, the program drops in an infinite loop. To avoid
this, it is necessary to provide correct instructions to the program that detects the end of the file.
Thus, when the end of the file is detected, the process of reading data can be easily terminated.
The eof() member function() is used for this purpose. The eof() stands for the end of
the file. It is an instruction ...