Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/io/iostream category"

From cppreference.com
< cpp‎ | io
m (Shorten template names. Use {{lc}} where appropriate.)
m (Update links.)
Line 40: Line 40:
 
===See also===
 
===See also===
 
{{dsc begin}}
 
{{dsc begin}}
{{dsc inc | cpp/io/ios_base/dcl list failure}}
+
{{dsc inc | cpp/io/ios_base/dsc failure}}
{{dsc inc | cpp/io/dcl list io_errc}}
+
{{dsc inc | cpp/io/dsc io_errc}}
 
{{dsc end}}
 
{{dsc end}}
  

Revision as of 22:03, 31 May 2013

Defined in header <ios>
const std::error_category& iostream_category();
(since C++11)

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

Contents

Parameters

(none)

Return value

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

Exceptions

noexcept specification:  
noexcept
  

Example

#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 category: " << e.code().category().name() << '\n';
    }
}

Output:

Caught an ios_base::failure.
Error category: iostream

See also

stream exception
(public member class of std::ios_base) [edit]
(C++11)
the IO stream error codes
(enum) [edit]