std::iostream_category
From cppreference.com
C++
Feature test macros (C++20)
Concepts library (C++20)
Metaprogramming library (C++11)
Ranges library (C++20)
Filesystem library (C++17)
Concurrency support library (C++11)
Execution control library (C++26)
Input/output library
Print functions (C++23)
Buffers
(C++23)
(C++98/26*)
(C++20)
Streams
Abstractions
File I/O
String I/O
Array I/O
(C++23)
(C++23)
(C++23)
(C++98/26*)
(C++98/26*)
(C++98/26*)
Synchronized Output
(C++20)
Types
Error category interface
iostream_category
(C++11)
(C++11)
Defined in header
<ios>
const std::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 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 .
[edit] Parameters
(none)
[edit] Return value
A reference to the static object of unspecified runtime type, derived from std::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 (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'; } }
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.
DR | Applied to | Behavior as published | Correct behavior |
---|---|---|---|
LWG 2087 | C++11 | iostream_category was not declared noexcept
|
declared noexcept |