名前空間
変種
操作

std::iostream_category

提供: cppreference.com
< cpp‎ | io
ヘッダ <ios> で定義
const std::error_category& iostream_category() noexcept;
(C++11以上)

入出力ストリームのエラーのための静的なエラーカテゴリオブジェクトを指す参照を取得します。 このオブジェクトは文字列 "iostream" を指すポインタを返すために仮想関数 error_category::name() をオーバーライドすることが要求されます。 std::ios_base::failure 型の例外で提供されるエラーコードを識別するために使用されます。

目次

[編集] 引数

(なし)

[編集] 戻り値

std::error_category から派生した未規定な実行時型の静的なオブジェクトを指す参照。

[編集]

#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';
 
    }
}

出力例:

Caught an ios_base::failure.
Error code: 1 (unspecified iostream_category error)
Error category: iostream

[編集] 関連項目

ストリームの例外
(std::ios_baseのパブリックメンバクラス) [edit]
(C++11)
iostream のエラーコード
(列挙) [edit]