fstream 中判断是否成功打开文件 | C++中文件流(fstream)的使用方法及示例

ifstream fin("filename");

if (!fin)
{
  cout << "fail to open the file" <<endl;
  return -1;//或者抛出异常。
}
else
{
  cout << "open the file successfully" << endl;
}

文件流参考链接

猜你喜欢

转载自blog.csdn.net/sinat_28442665/article/details/84629941