1.判断文件是否打开
if(a.fail())if(!a.good())
if(!a)
上面3个等价
但上面的无法检测到 : 以不合适的文件模式打开文件失败
a.is_open()可以检测到这个错误
所以推荐使用 if(!a.is_open())
2.
if( !fin ) { cout << "Error opening " << filename << " for input" << endl; exit(-1); }
1.判断文件是否打开
if(a.fail())if(!a.good())
if(!a)
上面3个等价
但上面的无法检测到 : 以不合适的文件模式打开文件失败
a.is_open()可以检测到这个错误
所以推荐使用 if(!a.is_open())
2.
if( !fin ) { cout << "Error opening " << filename << " for input" << endl; exit(-1); }