🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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?

  1. A.eof() is not a member of ifstream
  2. B.It never stops
  3. C.End of file is detected only after a read fails, so the loop body runs once more with stale data
  4. 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 →