C++ Filehandling: Difference between ios::app and ios::ate?

Adam_G picture Adam_G · Apr 28, 2012 · Viewed 80.8k times · Source

What's the difference between ios::ate and ios:app when writing to a file.
In my view, ios::app gives you the ability to move around in the file, whereas with ios::ate it can only read/write at the end of the file. Is this correct?

Answer

Jon Purdy picture Jon Purdy · Apr 28, 2012

It’s the other way around. When ios::ate is set, the initial position will be the end of the file, but you are free to seek thereafter. When ios::app is set, all output operations are performed at the end of the file. Since all writes are implicitly preceded by seeks, there is no way to write elsewhere.