Using a stream to enter text at the end of a file

How can I use a stream to write text to the end of a file without deleting its contents inside?

+3
source share
5 answers

When opening a file, you can pass the flag ios::app:

ofstream ofs("filename", ios::app);
+7
source

You want to add a file. Use ios :: app as the file mode when creating the stream.

Adding will automatically search for the end of the file.

+1
source

ios:: app .

0

seekp() .

0

, :

ofstream out("path_to_file",ios::app);

, .

, , ios::app, :

out.seekp(0,ios::end) This will place a pointer to 0 bytes from the end of the file. http://www.cplusplus.com/reference/ostream/ostream/seekp

Make sure you use the correct seekp (), as there are 2 seekp () overloads. In this situation, two parameters are preferred.

0
source

Source: https://habr.com/ru/post/1697767/


All Articles