小编slo*_*red的帖子

C++ ifstream错误检查

我是C++的新手,想要为我的代码添加错误检查,我想确保我使用良好的编码实践.我使用以下命令将ASCII文件中的一行读入字符串:

ifstream paramFile;
string tmp;

//open input file

tmp.clear();

paramFile >> tmp;

//parse tmp
Run Code Online (Sandbox Code Playgroud)
  1. 如何进行错误检查以确保输入文件读取成功?

  2. 我看到从那里读取ASCII文件的更复杂的方法.我这样做的方式是"安全/健壮"吗?

c++ error-handling ifstream

21
推荐指数
1
解决办法
3万
查看次数

标签 统计

c++ ×1

error-handling ×1

ifstream ×1