Ker*_* SB 29
对于文件,您可以寻找任何位置.例如,要回到开头:
std::ifstream infile("hello.txt");
while (infile.read(...)) { /*...*/ } // etc etc
infile.clear(); // clear fail and eof bits
infile.seekg(0, std::ios::beg); // back to the start!
Run Code Online (Sandbox Code Playgroud)
如果您已经阅读了结尾,则必须使用clear()@Jerry Coffin建议重置错误标记.