#include
#include
usingnamespace std; #ifdef WIN32 #define TEST_FILE "c://tmp//test.txt" #else #define TEST_FILE "/tmp/test.txt" #endif void get() { //ifstream ifs; //ifs.open(TEST_FILE); ifstream ifs(TEST_FILE); //while (ifs.good()) cout << (char) ifs.get();//simple while(ifs.good()){ char ch =0; //ch = ifs.get(); ifs.get(ch); cout << ch; } ifs.close(); } void getline() { //ifstream ifs; //ifs.open(TEST_FILE); ifstream ifs(TEST_FILE); while(ifs.good()) { char buf[1024]={0}; ifs.getline(buf, sizeof(buf)); cout << buf << endl; } ifs.close(); } int main(int argc, char* argv[]) { get(); getline(); return0; }
ifstream读取文件
最新推荐文章于 2024-08-20 21:41:54 发布