首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::iostream_category

Defined in header <ios>

?

?

const std::error_category& iostream_category();

?

(since C++11)

获取对iostream错误的静态错误类别对象的引用。对象需要重写虚拟函数。error_category::name()返回指向字符串的指针"iostream"它用于识别类型异常中提供的错误代码。std::ios_base::failure...

参数

%280%29

返回值

派生为未指定运行时类型的静态对象的引用。std::error_category...

例外

noexcept规格:

noexcept

二次

代码语言:javascript
复制
#include <iostream>
#include <fstream>
 
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"
                  << "Error code: " << e.code().value() 
                  << " (" << e.code().message() << ")\n"
                  << "Error category: " << e.code().category().name() << '\n';
 
    }
}

二次

可能的产出:

二次

代码语言:javascript
复制
Caught an ios_base::failure.
Error code: 1 (unspecified iostream_category error)
Error category: iostream

二次

另见

failure

stream exception (public member class of std::ios_base)

io_errc (C++11)

the IO stream error codes (enum)

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com