Namespaces
Variants

std:: iostream_category

From cppreference.net
< cpp ‎ | io
定義済みヘッダー <ios>
const std:: error_category & iostream_category ( ) noexcept ;
(C++11以降)

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

目次

パラメータ

(なし)

戻り値

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

#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"
                  << "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

不具合報告

以下の動作変更に関する欠陥報告書は、以前に公開されたC++規格に対して遡及的に適用されました。

DR 適用対象 公開時の動作 正しい動作
LWG 2087 C++11 iostream_category が宣言されていなかった noexcept 宣言されている noexcept

関連項目

ストリーム例外
( std::ios_base の公開メンバークラス)
(C++11)
IOストリームエラーコード
(列挙型)