一个读入文件的方法,这里调用了iostream
中的 getline
方法
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| #include <fstream> #include <iostream>
using namespace std;
int main() { char buff[100]; ifstream infile("t.txt"); cout << "reading from t.txt" << endl;
cout << "the data is: " << endl; while (!infile.eof()) { infile.getline(buff, 100); cout << buff << endl; } cout << "END!!" << endl; infile.close(); return 0; }
|