Possible Duplicate:
C++ Filehandling: Difference between ios:app and ios:ate?
What is the difference between these two file opening modes ?
ios:ate
sets the get/put pointer position to the end of the file so reading/writing will
begin from end, but how is it different from ios::app
, which again opens a file in append mode?
When I have created a ofstream
and opened it in `ios:app mode, the put stream pointer still points to the beginning, how does the appending work then?
Also, I understand that ifstream
, ofstream
, and fstream
are high-level classes to manage the underlying stream buffer.
Does it mean that even in ios:app
mode I can read data from a file?
ios::ate "sets the stream's position indicator to the end of the stream on opening." ios::app "set the stream's position indicator to the end of the stream before each output operation." This means the difference is that ios::ate puts your position to the end of the file when you open it.
ios::app. Opens an output file for appending only. ios::ate. Opens an existing file (either input or output) and seeks to the end.
ios::app (short for append) means that instead of overwriting the file from the beginning, all output operations are done at the end of the file. This is only meaningful if the file is also open for output. ios::trunc (short for truncate) means that when the file is opened, the old contents are immediately removed.
For example, one flag is <span class=\"code\">ios::nocreate </span>(which isn't included in newer compilers).</p>\n<p>This one means “only open the file if it already exists.” That is, don't create the file if it doesn't exist. (
app
comes from 'append' - all output will be added (appended) to the end of the file. In other words you cannot write anywhere else in the file but at the end.
ate
comes from 'at end' - it sets the stream position at the end of the file when you open it, but you are free to move it around (seek) and write wherever it pleases you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With