← Quiz: File Handling in C++: all 10 questions
Quiz: File Handling in C++ · Question 5 of 10
Why is while (!in.eof()) a bad way to read records?
Why is while (!in.eof()) a bad way to read records?
- A.eof() is not a member of ifstream
- B.It never stops
- C.End of file is detected only after a read fails, so the loop body runs once more with stale data
- D.It skips the first record
Answer & explanation
Correct answer: End of file is detected only after a read fails, so the loop body runs once more with stale data
The last record is processed twice; test the read itself instead.
Can you get the rest right without peeking?
Take the timed Quiz: File Handling in C++ quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →