简体   繁体   中英

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 : ABCD which is good, and than when i'm writing something for example E it writes it here ABECD this is really wierd, how can i fix it?

如果您使用std::ofstream并以附加模式打开文件(在模式掩码中使用std::ios_base::app ),则所有写操作都将在文件末尾进行。

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM