← Quiz: File Handling in C++: all 10 questions
Quiz: File Handling in C++ · Question 10 of 10
When does an ofstream declared inside { ... } close its file if you never call close()?
When does an ofstream declared inside { ... } close its file if you never call close()?
- A.Never; the file stays open until the computer restarts
- B.When the block ends and the stream's destructor runs
- C.Only when main returns
- D.After every << operation
Answer & explanation
Correct answer: When the block ends and the stream's destructor runs
File streams follow RAII: the destructor flushes and closes 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 →