What is the use of ios::trunc mode in C++?

Asked In: BPSC TRE 1.0

Options

  • A. To open a file in input mode
  • B. To open a file in output mode
  • C. To truncate an existing file to zero length
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

C. To truncate an existing file to zero length

Detailed Explanation

Correct Answer: Option C

Explanation: ios::trunc truncates an existing file to zero length when the file is opened successfully with this mode. It is commonly used with output file streams. Existing file contents are discarded.