Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/io/io errc"

From cppreference.com
< cpp‎ | io
(move dsc items to templates)
m (fmt, headers sorted, langlinks)
 
(4 intermediate revisions by 3 users not shown)
Line 2: Line 2:
 
{{cpp/io/io_errc/navbar}}
 
{{cpp/io/io_errc/navbar}}
 
{{dcl begin}}
 
{{dcl begin}}
{{dcl header | ios}}
+
{{dcl header|ios}}
{{dcl | notes={{mark since c++11}} | 1=
+
{{dcl|since=c++11|1=
enum class io_errc;
+
enum class io_errc {
 +
    stream = 1,
 +
};
 
}}
 
}}
 
{{dcl end}}
 
{{dcl end}}
  
The scoped enumeration {{tt|std::io_errc}} defines the error codes reported by I/O streams in {{lc|std::ios_base::failure}} exception objects. Only one error code ({{tt|std::io_errc::stream}}) is required, although the implementation may define additional error codes. Because the appropriate specialization of std::is_error_code_enum is provided, values of type {{tt|std::io_errc}} are implicitly convertible to {{lc|std::error_code}}.
+
The scoped enumeration {{tt|std::io_errc}} defines the error codes reported by I/O streams in {{lc|std::ios_base::failure}} exception objects. Only one error code ({{tt|std::io_errc::stream}}) is required, although the implementation may define additional error codes. Because the appropriate specialization of {{lc|std::is_error_code_enum}} is provided, values of type {{tt|std::io_errc}} are implicitly convertible to {{lc|std::error_code}}.
  
 
===Member constants===
 
===Member constants===
 
{{dsc begin}}
 
{{dsc begin}}
{{dsc hitem | Enumeration constant | Value}}
+
{{dsc hitem|Enumeration constant|Value}}
{{dsc | {{tt|stream}} | {{c|1}} }}
+
{{dsc|{{tt|stream}}|{{c|1}}}}
 
{{dsc end}}
 
{{dsc end}}
  
 
===Non-member functions===
 
===Non-member functions===
 
{{dsc begin}}
 
{{dsc begin}}
{{dsc inc | cpp/io/io_errc/dsc make_error_code}}
+
{{dsc inc|cpp/io/io_errc/dsc make_error_code}}
{{dsc inc | cpp/io/io_errc/dsc make_error_condition}}
+
{{dsc inc|cpp/io/io_errc/dsc make_error_condition}}
 
{{dsc end}}
 
{{dsc end}}
  
 
===Helper classes===
 
===Helper classes===
 
{{dsc begin}}
 
{{dsc begin}}
{{dsc inc | cpp/io/io_errc/dsc is_error_code_enum}}
+
{{dsc inc|cpp/io/io_errc/dsc is_error_code_enum}}
 
{{dsc end}}
 
{{dsc end}}
  
 
===Example===
 
===Example===
 
{{example
 
{{example
|
+
|code=
| code=
+
#include <iostream>
+
 
#include <fstream>
 
#include <fstream>
 +
#include <iostream>
 +
 
int main()
 
int main()
 
{
 
{
 
     std::ifstream f("doesn't exist");
 
     std::ifstream f("doesn't exist");
     try {
+
     try
 +
    {
 
         f.exceptions(f.failbit);
 
         f.exceptions(f.failbit);
     } catch (const std::ios_base::failure& e) {
+
     }
 +
    catch (const std::ios_base::failure& e)
 +
    {
 
         std::cout << "Caught an ios_base::failure.\n";
 
         std::cout << "Caught an ios_base::failure.\n";
         if(e.code() == std::io_errc::stream)
+
         if (e.code() == std::io_errc::stream)
 
             std::cout << "The error code is std::io_errc::stream\n";
 
             std::cout << "The error code is std::io_errc::stream\n";
 
     }
 
     }
 
}
 
}
| output=
+
|output=
 
Caught an ios_base::failure.
 
Caught an ios_base::failure.
 
The error code is std::io_errc::stream
 
The error code is std::io_errc::stream
Line 51: Line 56:
 
===See also===
 
===See also===
 
{{dsc begin}}
 
{{dsc begin}}
{{dsc inc | cpp/error/dsc error_code}}
+
{{dsc inc|cpp/error/dsc error_code}}
{{dsc inc | cpp/error/dsc error_condition}}
+
{{dsc inc|cpp/error/dsc error_condition}}
{{dsc inc | cpp/io/ios_base/dsc failure | mem=std::ios_base}}
+
{{dsc inc|cpp/io/ios_base/dsc failure|mem=std::ios_base}}
 
{{dsc end}}
 
{{dsc end}}
  
[[de:cpp/io/io errc]]
+
{{langlinks|de|es|fr|it|ja|pt|ru|zh}}
[[es:cpp/io/io errc]]
+
[[fr:cpp/io/io errc]]
+
[[it:cpp/io/io errc]]
+
[[ja:cpp/io/io errc]]
+
[[pt:cpp/io/io errc]]
+
[[ru:cpp/io/io errc]]
+
[[zh:cpp/io/io errc]]
+

Latest revision as of 10:50, 15 September 2023

 
 
 
std::io_errc
 
Defined in header <ios>
enum class io_errc {

    stream = 1,

};
(since C++11)

The scoped enumeration std::io_errc defines the error codes reported by I/O streams in std::ios_base::failure exception objects. Only one error code (std::io_errc::stream) is required, although the implementation may define additional error codes. Because the appropriate specialization of std::is_error_code_enum is provided, values of type std::io_errc are implicitly convertible to std::error_code.

Contents

[edit] Member constants

Enumeration constant Value
stream 1

[edit] Non-member functions

constructs an iostream error code
(function) [edit]
constructs an iostream error condition
(function) [edit]

[edit] Helper classes

extends the type trait std::is_error_code_enum to identify iostream error codes
(class template specialization) [edit]

[edit] Example

#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";
        if (e.code() == std::io_errc::stream)
            std::cout << "The error code is std::io_errc::stream\n";
    }
}

Output:

Caught an ios_base::failure.
The error code is std::io_errc::stream

[edit] See also

holds a platform-dependent error code
(class) [edit]
holds a portable error code
(class) [edit]
stream exception
(public member class of std::ios_base) [edit]