在c ++中清除文本文件内的数据 [英] clear data inside text file in c++

查看:138
本文介绍了在c ++中清除文本文件内的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C ++上编程。在我的代码中,我创建一个文本文件,写入数据到文件,并使用流从文件读取,在我完成序列后,我希望我清除所有的txt文件内的数据。有人可以告诉我命令清除txt文件中的数据。谢谢

I am programming on C++. In my code I create a text file, write data to the file and reading from the file using stream, after I finish the sequence I desire I wish to clear all the data inside the txt file. Can someone tell me the command to clear the data in the txt file. Thank you

推荐答案

如果您只是使用truncate-option打开文件,就会删除内容。 p>

If you simply open the file for writing with the truncate-option, you'll delete the content.

std::ofstream ofs;
ofs.open("test.txt", std::ofstream::out | std::ofstream::trunc);
ofs.close();

http://www.cplusplus.com/reference/fstream/ofstream/open/

这篇关于在c ++中清除文本文件内的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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