How can i write something to file at the end of the file in c++
i'm writing something to file and it writes it in the middle of the file开发者_如何学运维, is there any function that writes output to the end of the file? thanx in advance. ok this is really wierd i'm running with the visual studio debugger and i see that it writes thing to file like this : A B C D which is good, and than when i'm writing something for example E it writes it here A B E C D this is really wierd, how can i fix it?
If you use std::ofstream
and open the file in append mode (using std::ios_base::app
in the mode mask) then all writes will be made at the end of the file.
With the plain old C functions, open
the file with O_APPEND
or call lseek(fd, 0, SEEK_END)
before writing.
With ofstream
, call file.seekp(0, ios_base::end)
before writing.
精彩评论