What is the use of ios::trunc mode?

2023

What is the use of ios::trunc mode?

  1. A.

    To open a file in input mode

  2. B.

    To open a file in output mode

  3. C.

    To truncate an existing file to zero

  4. D.

    More than one of the above

  5. E.

    None of the above

Attempted by 104 students.

Show answer & explanation

Correct answer: C

ios::trunc mode is used when opening a file for output. It ensures that if the file already exists, its contents are truncated to zero length, effectively erasing all previous data. This mode is typically used with ofstream or fstream in C++ to start writing from a clean file.

Explore the full course: Uppsc Polytechnic Lecturer 2025 Cs