C++ 文件读取

时间:2022-11-01 15:36:34
#include <iostream>
#include <fstream>
#include <string> using namespace std; int main() { ifstream in;
in.open("test.txt");
if(!in){
cout << "open file failed !"<< endl;
return ;
} // char ch;
// // get a char
// while(in.read(&ch, 1)) { /// or replace with : in.get(ch)
// cout << ch << endl;
// } // get a line
char chr[];
while(in.getline(chr, )){
cout << chr <<endl;
}
in.close(); return ;
}

其他操作可参考:http://www.cnblogs.com/flatfoosie/archive/2010/12/22/1914055.html