pbuk
Science Advisor
Homework Helper
Gold Member
- 4,970
- 3,219
I don't find that strange: theyungman said:BUT it's strange, if I replace if(!people.eof()), it failed the first time without printing anything!
! is doing exactly what I would expect. Do you think it should be there?Well testing for eof would work in this case, but there are other reasons a read can fail so you should always check that a read has worked before you assume that it has and press on regardless.yungman said:I thought we should test for eof(), not fail. How do you know that?
It is also good practice not to return out of a loop like this, instead of return use break and after the loop you can then test to see whether the last record in the file was read successfully or not.