LearnFrenzy
Sign in Take a free test

File Handling (fstream) · File Handling MCQ · Question 9

Why call clear() on a stream? Answer, explanation & discussion

  • MCQ
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 9 Back to Exercise

After reading a file to the end, why must you call in.clear() before in.seekg(0) to read it again?

  • A To delete the file
  • B The eof/fail flags are still set, and a stream with error flags ignores further operations Correct
  • C To flush output
  • D It is not necessary
Correct Answer: Option B

C++11 seekg clears eofbit, but failbit (set by the last failed read) must still be cleared.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links