views:

234

answers:

4
+3  Q: 

Fstreams C++

Hello
I want the ofstream to write at the end of a file without erasing its content inside.
how can i do it? (i'm talking about txt files,and C++)
Thanks.

+7  A: 

You can pass the flag ios::app when opening the file:

ofstream ofs("filename", ios::app);
Konrad Rudolph
A: 

Use ios::app as the file mode.

KernelM
+1  A: 

You want to append to the file. Use ios::app as the file mode when creating the ofstream.

Appending will automatically seek to the end of the file.

Ed Haber
A: 

you can also manually move the pointer once the file is open using seekp()

Nona Urbiz