OverWrite text file

I dont know how to overwrite a text file data, i tryed some of the google found one's but those dosent work. Anyone can say me how and explain me?

ex: in value.txt i have 0, i get a new value (100) from my code, how to delete 0 and write 100?
Thanks in advance!

EDIT: There's no any way? :(, no one is reply'ing :(
Last edited on
closed account (1vD3vCM9)
I'm afraid you will need file parsing, it is not that simple.
closed account (E0p9LyTq)
To "erase" the contents of a file before writing new content, open the file with the trunc filestream mode:

1
2
3
4
5
6
7
8
9
10
#include <fstream>

int main ()
{
   std::ofstream ofs("test.txt", std::ofstream::trunc);

   ofs << "lorem ipsum";

   ofs.close();
}


http://www.cplusplus.com/reference/fstream/ofstream/ofstream/
+FurryGuy
Thanks, i edit-ed something but i used it too!

+oren dropitsky
Any reply's are helpful. :D
Last edited on
Topic archived. No new replies allowed.