Multiple choice

Which one of the following file modes allows us to add data or to modify the existing data anywhere in the file?

  1. ios::app

  2. ios::ate

  3. ios::out

  4. ios::trunc

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

ios::ate (at end) opens the file and positions the pointer at end, but allows reading/writing anywhere in the file. ios::app only allows appending at end. ios::trunc discards existing content. ios::ate provides random access.