This question asks the difference between app
and ate
and both the answers and cppreference imply that the only difference is that app
means that the write cursor is put at the end of the file before each write operation, whereas ate
means that the write cursor is put at the end of the file only when opening.
What I'm actually seeing (in VS 2012) is that specifying ate
discards the contents of an existing file, whereas app
does not (it appends new content to the previously existing content). In other words, ate
seems to imply trunc
.
The following statement appends "Hello" to an existing file:
ofstream("trace.log", ios_base::out|ios_base::app) << "Hello\n";
But the following statement replaces the contents of the file with just "Hello":
ofstream("trace.log", ios_base::out|ios_base::ate) << "Hello\n";
The MSDN documentation for VS 6.0 implies that shouldn't happen (but this sentence seems to have been withdrawn in later versions of Visual Studio):
ios::trunc: If the file already exists, its contents are discarded. This mode is implied if ios::out is specified, and ios::ate, ios::app, and ios:in are not specified.