文件指针回到开头

    技术2022-05-18  13

    #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函数的使用!


    最新回复(0)