I/O manipulators | ||||
Print functions(C++23) | ||||
C-style I/O | ||||
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 | ||||
(C++11) | ||||
(C++11) |
C++ includes the following input/output libraries: anOOP-stylestream-based I/O library,print-based family of functions(since C++23), and the standard set ofC-style I/O functions.
Contents |
The stream-based input/output library is organized around abstract input/output devices. These abstract devices allow the same code to handle input/output to files, memory streams, or custom adaptor devices that perform arbitrary operations (e.g. compression) on the fly.
Most of the classes are templated, so they can be adapted to any basic character type. Separate typedefs are provided for the most common basic character types (char andwchar_t). The classes are organized into the following hierarchy:
Inheritance diagram
Abstraction | |
Defined in header <ios> | |
manages formatting flags and input/output exceptions (class)[edit] | |
manages an arbitrary stream buffer (class template)[edit] | |
Defined in header <streambuf> | |
abstracts a raw device (class template)[edit] | |
Defined in header <ostream> | |
wraps a given abstract device (std::basic_streambuf) and provides high-level output interface (class template)[edit] | |
Defined in header <istream> | |
wraps a given abstract device (std::basic_streambuf) and provides high-level input interface (class template)[edit] | |
wraps a given abstract device (std::basic_streambuf) and provides high-level input/output interface (class template)[edit] | |
File I/O implementation | |
Defined in header <fstream> | |
implements raw file device (class template)[edit] | |
implements high-level file stream input operations (class template)[edit] | |
implements high-level file stream output operations (class template)[edit] | |
implements high-level file stream input/output operations (class template)[edit] | |
String I/O implementation | |
Defined in header <sstream> | |
implements raw string device (class template)[edit] | |
implements high-level string stream input operations (class template)[edit] | |
implements high-level string stream output operations (class template)[edit] | |
implements high-level string stream input/output operations (class template)[edit] | |
Array I/O implementations | |
Defined in header <spanstream> | |
(C++23) | implements raw fixed character buffer device (class template)[edit] |
(C++23) | implements fixed character buffer input operations (class template)[edit] |
(C++23) | implements fixed character buffer output operations (class template)[edit] |
(C++23) | implements fixed character buffer input/output operations (class template)[edit] |
Defined in header <strstream> | |
(deprecated in C++98)(removed in C++26) | implements raw character array device (class)[edit] |
(deprecated in C++98)(removed in C++26) | implements character array input operations (class)[edit] |
(deprecated in C++98)(removed in C++26) | implements character array output operations (class)[edit] |
(deprecated in C++98)(removed in C++26) | implements character array input/output operations (class)[edit] |
Synchronized output(since C++20) | |
Defined in header <syncstream> | |
(C++20) | synchronized output device wrapper (class template)[edit] |
(C++20) | synchronized output stream wrapper (class template)[edit] |
The following typedefs for common character types are provided in namespacestd
:
Defined in header <iostream> | |
reads from the standard C input streamstdin (global object)[edit] | |
writes to the standard C output streamstdout (global object)[edit] | |
writes to the standard C error streamstderr, unbuffered (global object)[edit] | |
writes to the standard C error streamstderr (global object)[edit] |
The stream-based I/O library usesI/O manipulators (e.g.std::boolalpha,std::hex, etc.) to control how streams behave.
The following auxiliary types are defined:
Defined in header <ios> | |
represents relative file/stream position (offset from fpos), sufficient to represent any file size (typedef)[edit] | |
represents the number of characters transferred in an I/O operation or the size of an I/O buffer (typedef)[edit] | |
represents absolute position in a stream or a file (class template)[edit] |
The following typedef names forstd::fpos<std::mbstate_t> are provided:
Defined in header <iosfwd> | |
Type | Definition |
std::streampos | std::fpos<std::char_traits<char>::state_type> |
std::wstreampos | std::fpos<std::char_traits<wchar_t>::state_type> |
std::u8streampos (C++20) | std::fpos<std::char_traits<char8_t>::state_type> |
std::u16streampos (C++11) | std::fpos<std::char_traits<char16_t>::state_type> |
std::u32streampos (C++11) | std::fpos<std::char_traits<char32_t>::state_type> |
Defined in header <ios> | |
(C++11) | the IO stream error codes (enum)[edit] |
(C++11) | identifies the iostream error category (function)[edit] |
The Unicode-aware print-family functions that perform formatted I/O on text that is already formatted. They bring all the performance benefits ofstd::format, are locale-independent by default, reduce global state, avoid allocating a temporarystd::string object and callingoperator<<, and in general make formatting more efficient compared toiostreams andstdio.
The following print-like functions are provided:
Defined in header <print> | |
(C++23) | prints tostdout or a file stream usingformatted representation of the arguments (function template)[edit] |
(C++23) | same asstd::print except that each print is terminated by additional new line (function template)[edit] |
prints to Unicode capablestdout or a file stream usingtype-erased argument representation (function)[edit] | |
prints tostdout or a file stream usingtype-erased argument representation (function)[edit] | |
Defined in header <ostream> | |
(C++23) | outputsformatted representation of the arguments (function template)[edit] |
(C++23) | outputsformatted representation of the arguments with appended'\n' (function template)[edit] |
C++ also includes theinput/output functions defined by C, such asstd::fopen,std::getc, etc.
Filesystem library(since C++17) |