c++读写文件

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main() {

//往文件里写

ofstream f;
f.open("test.txt",ios::out);
f << "aaaaaa" << endl;

//读文件
ifstream f;
f.open("test.txt",ios::in);
string buf;
while (getline(f, buf)) {
cout << buf << endl;
}


f.close();
system("pause");
return 0;
}

 

posted @ 2022-10-12 14:49  笨笨和呆呆  阅读(23)  评论(0)    收藏  举报