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);  
    }

 

相关文章:

  • 2022-02-24
  • 2022-01-18
  • 2022-12-23
猜你喜欢
  • 2021-07-28
  • 2021-06-01
  • 2021-12-31
  • 2021-10-21
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案