← Quiz: File Handling in C++: all 10 questions
Quiz: File Handling in C++ · Question 2 of 10
What happens when you open an existing file with ofstream out("data.txt");?
What happens when you open an existing file with ofstream out("data.txt");?
- A.New data is added at the end
- B.It fails because the file exists
- C.The old contents are erased and writing starts from the beginning
- D.The file is opened read-only
Answer & explanation
Correct answer: The old contents are erased and writing starts from the beginning
ios::out without ios::app truncates 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 →