C++写入txt

在C++中对文件进行操作,要包含头文件

#include <fstream>
using namespace std;

创建对象(简单举例):

ofstream outfile;
outfile.open("data.txt")

写入内容

outfile<<要写入的内容<<"\n";

关闭文件,保存文件。

outfile.close()

  

  

  

posted @ 2019-05-21 14:57  奥布莱恩  阅读(940)  评论(0编辑  收藏  举报