Input/output library
C++ includes the following input/output libraries: an OOP-style stream-based I/O library, print-based family of functions(since C++23), and the standard set of C-style I/O functions.
[edit] Stream-based I/O
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 and wchar_t). The classes are organized into the following hierarchy:
Inheritance diagram
Abstraction
<ios>
<streambuf>
<ostream>
and provides high-level output interface
(class template) [edit]
<istream>
and provides high-level input interface
(class template) [edit]
and provides high-level input/output interface
(class template) [edit]
File I/O implementation
<fstream>
String I/O implementation
<sstream>
Array I/O implementations
<spanstream>
<strstream>
(class) [edit]
Synchronized output (since C++20)
<syncstream>
[edit] Typedefs
The following typedefs for common character types are provided in namespace std
:
<ios>
<streambuf>
<istream>
<ostream>
<fstream>
<sstream>
<spanstream>
<syncstream>
[edit] Predefined standard stream objects
<iostream>
[edit] I/O Manipulators
The stream-based I/O library uses I/O manipulators (e.g. std::boolalpha , std::hex , etc.) to control how streams behave.
[edit] Types
The following auxiliary types are defined:
<ios>
(typedef) [edit]
(typedef) [edit]
The following typedef names for std::fpos <std::mbstate_t > are provided:
<iosfwd>
std::streampos
std::fpos <std::char_traits <char>::state_type>
std::wstreampos
std::fpos <std::char_traits <wchar_t>::state_type>
[edit] Error category interface (since C++11)
<ios>
[edit] Print functions (since C++23)
The Unicode-aware print-family functions that perform formatted I/O on text that is already formatted. They bring all the performance benefits of std::format , are locale-independent by default, reduce global state, avoid allocating a temporary std::string object and calling operator<<, and in general make formatting more efficient compared to iostreams and stdio.
The following print-like functions are provided:
<print>
(function template) [edit]
(function template) [edit]
(function) [edit]
<ostream>
(function template) [edit]
[edit] C-style I/O
C++ also includes the input/output functions defined by C, such as std::fopen , std::getc , etc.