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