difference between ios::ate and ios::trunc

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
std::ios::app doesn't truncate the file when it is opened, and std::ios::ate puts the file pointer at the end 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
Well, I think I made a mistake. What I meant was
What is the difference between trunc and ate


But thanks anyways for the explanation!
Oops. I completely misread that.

std::ios::trunc ensures that the file will be truncated.
Topic archived. No new replies allowed.