Resetting the End of file state of a ifstream object in C++
问题 I was wondering if there was a way to reset the eof state in C++? 回答1: For a file, you can just seek to any position. For example, to rewind to the beginning: 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! If you already read past the end, you have to reset the error flags with clear() as @Jerry Coffin suggests. 回答2: Presumably you mean on an iostream. In this