Mar 18, 2010 at 5:27am Mar 18, 2010 at 5:27am UTC
Can anyone explain what the difference between using flag trunc and ate is?
It'd be nice if you could give some examples to show the difference.
By the way, what does "ate" stand for?
EDIT: I have replaced app with trunc, as what I really meant was what is the difference between trunc and ate?
Last edited on Mar 18, 2010 at 7:41pm Mar 18, 2010 at 7:41pm UTC
Mar 18, 2010 at 6:54am Mar 18, 2010 at 6:54am UTC
std::ios::app doesn't truncate the file when it is opened, and std::ios::ate puts the file pointer
at the
e nd of the file. This is useful to get the file size:
1 2
std::ifstream file("file.txt" ,std::ios::binary|std::ios::ate);
unsigned long size=file.tellg();
Without std::ios::ate, you'd have to call
file.seekg(0,std::ios::end)
before line 2.
Last edited on Mar 18, 2010 at 6:56am Mar 18, 2010 at 6:56am UTC
Mar 18, 2010 at 9:44pm Mar 18, 2010 at 9:44pm UTC
Oops. I completely misread that.
std::ios::trunc ensures that the file will be truncated.