1、添加头文件
#include <fstream>
2、打开txt文件
ofstream outfile("test.txt",std::ios::app);
3、写入txt
outfile << "Hello World!" << std::endl;
4、关闭
outfile.close()
本文介绍使用C++进行文件操作的基本步骤,包括添加头文件、打开文件、写入内容及关闭文件。通过示例代码展示了如何向TXT文件中写入文本。
1、添加头文件
#include <fstream>
2、打开txt文件
ofstream outfile("test.txt",std::ios::app);
3、写入txt
outfile << "Hello World!" << std::endl;
4、关闭
outfile.close()
2万+
3987

被折叠的 条评论
为什么被折叠?