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?
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.
iostream
打开模式大致对应于C库中的fopen
模式,而fopen
具有截断的w
模式和附加a
模式,但不能将两者组合。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.