← 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?
- A.while (!in.eof()) { getline(in, line); ... }
- B.while (getline(in, line)) { ... }
- C.for (int i = 0; i < in.size(); i++) { ... }
- 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 →