【发布时间】:2012-09-19 12:51:59
【问题描述】:
在C++中,有没有std::ifstream open()可以成功,而std::ifstream good()可以为假的情况?
编辑:用 g++ 4.7.1 测试
#include <iostream>
#include <fstream>
int main(int argc, char *argv[])
{
std::ifstream filestream("testfile");
std::cout<<filestream.good()<<std::endl;
std::cout<<filestream.eof()<<std::endl;
std::cout<<filestream.fail()<<std::endl;
std::cout<<filestream.bad()<<std::endl;
return 0;
}
将为空文件返回:1, 0, 0, 0,这意味着 good = TRUE 和 eof = fail = bad = FALSE。正常吗?
【问题讨论】: