【发布时间】:2021-07-18 02:40:10
【问题描述】:
std::filesystem::exists 用于检查“给定的文件状态或路径是否对应于现有文件或目录”。在我的代码中,我使用具有以下签名的定义:
bool exists( const std::filesystem::path& p, std::error_code& ec ) noexcept;
我的问题是:如果函数返回布尔值true,我还需要检查错误代码ec的值吗?或者我可以假设,如果std::filesystem::exists 返回true,那么没有错误并且(bool)ec 是false?
例如,假设我有以下内容:
std::error_code ec;
std::filesystem::path fpath = "fname";
bool does_exist = std::filesystem::exists(fpath, ec);
if (does_exist) {
...
}
是否有必要检查(bool)ec == false 是否在if (does_exist) { ... } 块内?
【问题讨论】:
标签: c++ c++17 error-code