C++写入txt

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

#include <fstream>
using namespace std;

创建对象(简单举例):

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

写入内容

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

关闭文件,保存文件。

outfile.close()

  

  

  

猜你喜欢

转载自www.cnblogs.com/lzq116/p/10899839.html