如何编写文本文件的延续? [英] How can i write continuation of a text file?

查看:124
本文介绍了如何编写文本文件的延续?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨.
我有功能,我不知道发生了什么事件.而且我在很多主要情况下都使用过它,如果我通过"ostream"编写文件,则事件被成功写入,但是当调用该函数时,事件将从文本文件中清除,并且从第一个文件开始写入文件!!
那么,我如何在文件(例如文本文件)中以附录的形式继续书写?

Hi.
I have function and i do not know what events are occurred in it. And I used it in many of the main, If i write a file by "ostream" , events are wrote successfully but when the function recalled, the events are cleaned from the text file and it start''s to write from the first of the file!!
So, How can i write as appendix in a file ( such as text files ) for continuation?
How do I append to an existing text file?

推荐答案

使用seekp将指针设置为文件末尾.

有关详细信息,请阅读: ostream :: seekp [
Use seekp to set the pointer to the end of the file.

For details read this: ostream::seekp[^]


我建​​议您改用fstream.它将允许您指定打开文件的模式-因此您可以指定是追加还是截断现有文件.

参见此处:
http://www.cplusplus.com/reference/iostream/fstream/open/ [ ^ ]
I suggest you use fstream instead. It will allow you to specify the mode in which the fie is opened - so you can specify whether to append or truncate an existing file.

See here: http://www.cplusplus.com/reference/iostream/fstream/open/[^]


这篇关于如何编写文本文件的延续?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆