Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between ios::app and ios::ate? [duplicate]

Tags:

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?

like image 241
Arun Avatar asked Oct 17 '12 07:10

Arun


People also ask

What is the difference between ios :: ate and ios :: app?

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.

What is use of ios :: app mode in file opening?

ios::app. Opens an output file for appending only. ios::ate. Opens an existing file (either input or output) and seeks to the end.

What happens when we open a file in ios :: trunc mode and ios :: app mode?

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.

What is ios :: Nocreate in C++?

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. (


1 Answers

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.

like image 94
tozka Avatar answered Oct 26 '22 05:10

tozka