1.读取数据文件
#include<iostream>
#include<fstream>//文件流
using namespace std;
int main() {
ifstream in("1.txt");
if (!in.is_open()) {
return 1;
}
int x;
while (!in.eof()) {
in >> x;
if (!in)break;
cout << x << endl;
}
return 0;
}
2.读取字符串
#include<iostream>
#include<fstream>//文件流
using namespace std;
int main()
{
ifstream in("3.txt");
char buf[100];
while (in.getline(buf, sizeof(buf))) {
cout << buf << endl;
}
return 0;
}