3
简单代码:对已经“EOF”ed执行peek()是否继续返回EOF?
std::ifstream file("file.txt");
std::string line;
while(getline(file,line))
; //exhaust file
//in this sample code, for simplicity assert that the only possible "fail"
//is EOF (which it will always be under normal circumstances).
assert(!file.fail() || file.eof());
assert(file.peek() == EOF); //does this always hold?
将最终断言总是成功?
问题解释:EOF之后的位置是否也返回EOF?
该文档没有清楚地提到peek()在流在EOF处已经是什么时做了什么,所以我的问题。
我无法找到/引用规范的特定部分,但是如果它不能以这种方式工作,那将是相当愚蠢的[当然,周围有一些愚蠢的接口,这就是为什么我想要看到一个指定它的文档]。 – 2013-02-24 16:37:15