What is the quickest way to erase the contents of an fstream? I don't want to delete the file, just make it blank.
Printable View
What is the quickest way to erase the contents of an fstream? I don't want to delete the file, just make it blank.
The simplest way is to open the file for writing. This should automatically clear all previous data in the file and set the position pointer to 0.
-Prelude
So the following line will erase the contents of a.txt?
Code:fstream target( "a.txt", ios :: out );
Also, is there any easy way to get the name of the file which the fstream was opened on? That is, given an fstream, can you give me the name of the file the fstream is "pointing to"?
>So the following line will erase the contents of a.txt?
Yes
>is there any easy way to get the name of the file which the fstream was opened on?
Nothing portable that I can think of off-hand except for having a string which holds the name of the file.
-Prelude
Thanks for your help!