All output operations happen at the end of the file, appending to its existing contents.

trunc

truncate

Any contents that existed in the file before it is open are discarded.

These flags can be combined with the bitwise OR operator (|).
* out is always set for basic_ofstream objects (even if explicitly not set in argument mode).
Note that even though basic_ofstream is an output stream, its internal basic_filebuf object may be set to also support input operations.

If the mode has both trunc and app set, the opening operation fails. It also fails if both app and in are set simultaneously.

If the mode has both trunc and app set, the opening operation fails.

Return Value

none

If the function fails to open a file, the failbitstate flag is set for the stream (which may throw ios_base::failure if that state flag was registered using member exceptions).

Data races

Exception safety

Basic guarantee: if an exception is thrown, the stream is in a valid state.
It throws an exception of member type failure if the function fails (setting the failbit state flag) and member exceptions was set to throw for that state.