ate
simply positions you at the end of file after opening, and nothing else. It's not much use on an ofstream
, at least without other flags, since the file will have been truncated anyway, so the beginning is the end. (To avoid truncation, and still be able to write anywhere in the file, you need to or in ios::in
as well, even if you're not going to read.)
app
prevents the truncation of an existing file, and causes every write to go to the end of the file. Atomically, if possible; if other processes are writing to the same file, your write should still go to the end. Note however that this refers to the actual system level write. If, however, you are writing lines which are less than the buffer size, and you terminate each line with std::endl
, you can count on each line being appended atomically, regardless of what other processes might be doing with the file. To be effective, you'll probably want to use pubsetbuf
on the filebuf
as well, to ensure a minimum buffer size.
In practice, I don't think I've ever used either of them, or found them of any use. The buffering issues with app
, in particular, have generally led me to write my own streambuf
, with conceptually unlimited buffering (an std::vector<char>
as buffer), which opens the underlying system file with the equivalent of app
, but guarantees only writing to it when explicitly flushed (as with `std::endl).