🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← All topics

Quiz: File Handling in C++: questions with answers

10 questions, each with the answer and a short explanation.

Take the timed quiz + get a certificate →
  1. Q1. Which class do you use to read data from a file?
  2. Q2. What happens when you open an existing file with ofstream out("data.txt");?
  3. Q3. Which loop reads every line of a file correctly?
  4. Q4. What does this print? (code)
  5. Q5. Why is while (!in.eof()) a bad way to read records?
  6. Q6. Which mode flag makes every write go to the end of the file?
  7. Q7. What does this print? (code)
  8. Q8. In a binary file of fixed-size Student records, where does record number k (counting from 0) start?
  9. Q9. Why should you not save a struct containing a std::string with write()?
  10. Q10. When does an ofstream declared inside { ... } close its file if you never call close()?