Originally Posted by the website I posted Above
End of File Function
So, just how much data is in that file? The contents of an input file may not be precisely known. Usually the general format of the file and the type of data needed to receive the input are known. The amount of data stored in the file is often indefinite. So, do we spend our time counting data in a text file, or do we let the computer deal with the amount of data? Of course, we let the computer do the counting. C++ provides a special function, eof( ), that returns nonzero (meaning TRUE) when there are no more data to be read from an input file stream, and zero (meaning FALSE) otherwise.
Rules for using end-of-file (eof( )):
1. Always test for the end-of-file condition before processing data read from an input file stream.
a. use a priming input statement before the loop
b. use an input statement at the bottom of the loop
2. Use a while loop for getting data from an input file stream. A for loop is desirable only when you know the exact number of data items in the file.