Reputation: 3155
It took me quite a while to figure out that my .open()
call wasn't opening a file because I had both the trunc
and app
mode options set. I only figured this out after catching a little note written on the C++ docs.
This seems like a weird gotcha. Why is this the case? Can you not truncate the file and then append only? Or is this considered superfluous specification?
Upvotes: 3
Views: 649
Reputation: 490108
The allowable combinations of flags are specified in [filebuf.members] in the standard. Table 132 gives the possibilities:
So, since the combination of trunc
and app
isn't in the table, the open is required to fail.
Upvotes: 4
Reputation: 171263
The iostream
open modes correspond roughly to the fopen
mode in the C library and fopen
has a w
mode that truncates and an a
mode that appends, but no combination of the two.
Upvotes: 2