How do I clear a file?

Is there any way to clear a file on/immediately after opening it with ofstream? When I use ios_base::trunc, it gives me errors, whether the file exists or not or has data in it or not. Why would this even happen?
Last edited on
Could we see the code that's causing errors? That might help us in answering your question.

-Albatross
Save.open(FilePath.c_str(), ios_base::out|ios_base::binary|ios_base::trunc|ios_base::app);

FilePath is a std::string, and Save is, of course, my ofstream.

If I remove ios_base::trunc, then it works fine, but it keeps the data that was already in the file before.
remove ios_base::app
Topic archived. No new replies allowed.