🎙 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 3 of 10

Which loop reads every line of a file correctly?

Which loop reads every line of a file correctly?

  1. A.while (!in.eof()) { getline(in, line); ... }
  2. B.while (getline(in, line)) { ... }
  3. C.for (int i = 0; i < in.size(); i++) { ... }
  4. D.while (in) { ... } without reading inside
Answer & explanation

Correct answer: while (getline(in, line)) { ... }

getline returns the stream, which is false once a read fails at the end of the file.

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 →