🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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");?

  1. A.New data is added at the end
  2. B.It fails because the file exists
  3. C.The old contents are erased and writing starts from the beginning
  4. 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 →