R. Clayton (rclayton@monmouth.edu)
Thu, 27 Jul 2000 19:18:13 -0400 (EDT)
Almost everybody is making the same subtle programming error in their code:
while (!in.eof())
mbox.push_back(in.get());
Code written like this demonstrates a misunderstanding about the way file-io
works: you can't detect the end-of-file until you try to read a character; only
after you've tried to read a character can the end-of-file be detected. The
code above always makes one extra iteration of the loop, even on empty files.
You should study this code until you understand why it's wrong, and then never
write code like this again.
This archive was generated by hypermail 2.0b3 on Fri Aug 11 2000 - 15:25:05 EDT