One.输出到文件
#include<bits/stdc++.h>
using namespace std;
int main() {
ofstream outfile;
outfile.open("e:\\aaa123.txt");//输出路径
outfile << "输出的内容" << endl;//文件内容
outfile << "输出" << endl;//文件内容
outfile.close();
return 0;
}
Two.读入文件,输入
#include<bits/stdc++.h>
using namespace std;
int main() {
char line[50];
ifstream ifile("./text.txt"); //文件路径
while (ifile.getline(line, sizeof(line))) {
cout << line << endl;
}
ifile.close();
return 0;
}