For Advanced Readers

We have discussed exiting loop with function eof() in section 14.4.5. This strategy was not implemented in program.14.4 It did not produce errors. The reason is reading a string is coded differently from reading integers or floats. When we read a string which is at the end of the file, function end of file flag is marked (unlike) integer. We will say that the program worked correctly because we were lucky. Consider a case of counting the lines read in that program. We would have get value 0 when the file is empty. However, you will get wrong value of one. Therefore, we will recommend the strategy discussed earlier even when we are reading strings.

Get Object Oriented Programming with C++, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.