有没有办法检查 ifstream 中是否有任何字符可供读取,如果有,我该怎么做。如果您确定这是不可能的,请告诉我。
最佳答案
要在编辑后获得您要询问的内容,您可以使用 peek()功能:
给定一个名为 f
的 std::ifstream
if (f && f.peek() == EOF)
std::cout << "Nothing left to read\n";
else
std::cout << "There is something to read or the stream is bad\n";
但请记住,这不是一个“更一般”的问题,而是一个不同的问题(也就是说,将其应用于您的原始问题将是错误的)
关于C++ std::ifstream:检查字符是否留待读取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16596830/