#include <iostream>
#include <fstream>
using namespace std;
int main()
{
const char *filename = "t.txt";
ofstream ofile;
ifstream ifile;
//write
ofile.open(filename);
ofile << "111111111111" << endl;
ofile << "222222222222" << endl;
ofile.close();
//read
string str;
ifile.open(filename);
while(ifile >> str)
cout << str << endl;
ifile.close();
return 0;
}
Sample of C++ read/write a text file
最新推荐文章于 2024-12-11 17:52:46 发布
本文提供了一个使用C++进行文件读写的简单示例。代码首先创建并写入了一个包含两行字符串的文本文件,然后立即读取该文件并打印其内容。此示例适用于初学者了解基本的文件操作。
3万+

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



