文件指针回到开头

#include <stdio.h> #include <iostream> #include <fstream> using namespace std; int main() { ifstream in; in.open("b.cpp"); string temp; while (getline(in, temp)) { cout << temp << endl; } in.clear(); in.seekg(0, ios::beg); while (getline(in, temp)) { cout << temp << endl; } return 0; }

要注意clear函数的使用!

你可能感兴趣的:(ios,String,include)