读取文件的四种方式:
#include#include #include #include #include #include using namespace std; using namespace cv; void test02() { ifstream ifs; ifs.open("test01.txt", ios::in); if (!ifs.is_open()) { cout << "读取文件失败" << endl; return; } //第一种读取文件的方式 //char buf[1024] = { 0 }; //while (ifs >> buf) { // cout << buf << endl; //} //第二种读取文件的方式 //char buf[1024] = { 0 }; //while (ifs.getline(buf, sizeof(buf))) { // cout << buf << endl; //} // 第三种读取文件的方式 //第四种读取文件的方式 char c;//逐个字符读取,效率低下,不推荐 while ((c = ifs.get()) != EOF){ cout << c ; } ifs.close(); } int main() { test02(); system("pause"); return 0; }



