std:: is_error_code_enum <std::io_errc>
|
定义于头文件
<ios>
|
||
|
template
<>
struct is_error_code_enum < std:: io_errc > : public std:: true_type { } ; |
(C++11 起) | |
此 std::is_error_code_enum 的特化向其他库组件表明,类型为 std::io_errc 的值是包含错误代码的枚举类型,这使得它们可以隐式转换并赋值给类型为 std::error_code 的对象。
目录 |
继承自 std:: integral_constant
成员常量
|
value
[静态]
|
true
(公开静态成员常量) |
成员函数
|
operator bool
|
将对象转换为
bool
,返回
value
(公开成员函数) |
|
operator()
(C++14)
|
返回
value
(公开成员函数) |
成员类型
| 类型 | 定义 |
value_type
|
bool |
type
|
std:: integral_constant < bool , value > |
示例
e. code ( ) 与 std::io_errc::stream 之间的比较能够编译通过,是因为 std:: is_error_code_enum < std:: io_errc > :: value == true 。
#include <fstream> #include <iostream> int main() { std::ifstream f("doesn't exist"); try { f.exceptions(f.failbit); } catch (const std::ios_base::failure& e) { std::cout << "Caught an ios_base::failure.\n"; if (e.code() == std::io_errc::stream) std::cout << "The error code is std::io_errc::stream\n"; } }
输出:
Caught an ios_base::failure. The error code is std::io_errc::stream
参见
|
(C++11)
|
标识类为
error_code
枚举类型
(类模板) |
|
(C++11)
|
保存平台相关的错误代码
(类) |
|
(C++11)
|
IO流错误代码
(枚举) |