Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::iostream_category

      From cppreference.com
      <cpp‎ |io
       
       
       
      Defined in header<ios>
      conststd::error_category& iostream_category()noexcept;
      (since C++11)

      Obtains a reference to the static error category object for iostream errors. The object is required to override the virtual functionerror_category::name() to return a pointer to the string"iostream". It is used to identify error codes provided in the exceptions of typestd::ios_base::failure.

      Contents

      [edit]Parameters

      (none)

      [edit]Return value

      A reference to the static object of unspecified runtime type, derived fromstd::error_category.

      [edit]Example

      Run this code
      #include <fstream>#include <iostream> int main(){std::ifstream f("doesn't exist");try{        f.exceptions(f.failbit);}catch(conststd::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'; }}

      Possible output:

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

      [edit]Defect reports

      The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

      DRApplied toBehavior as publishedCorrect behavior
      LWG 2087C++11iostream_category was not declarednoexceptdeclarednoexcept

      [edit]See also

      stream exception
      (public member class ofstd::ios_base)[edit]
      (C++11)
      the IO stream error codes
      (enum)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/io/iostream_category&oldid=157068"

      [8]ページ先頭

      ©2009-2025 Movatter.jp