Detection of the end-of-file condition is necessary for preventing any further attempt to
read data from the file.
An ifstream object, such as fin, returns a value of 0 if any error occurs in the file operation including the end-of-file condition. Thus, the while loop terminates when fin returns a value of zero on reaching the end-of-file condition. Remember, this loop may terminate due to other failures as well......There is another approach to detect the end-of-file
eof() is a member function of ios class. It returns a non-zero value if the end-of-file(EOR) condition
is encountered and a zero, otherwise. Therefore, the above statement terminates
the program on reaching the end of the file.