| 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) |
| Global objects | ||||
| Member functions | ||||
(C++11) | ||||
| Formatted output | ||||
basic_ostream::operator<< | ||||
| Unformatted output | ||||
| Positioning | ||||
| Miscellaneous | ||||
(C++11) | ||||
| Member classes | ||||
| Non-member functions | ||||
(C++23) | ||||
(C++23) | ||||
(C++23) | ||||
basic_ostream& operator<<(bool value); | (1) | |
basic_ostream& operator<<(long value); | (2) | |
basic_ostream& operator<<(unsignedlong value); | (3) | |
basic_ostream& operator<<(longlong value); | (4) | (since C++11) |
basic_ostream& operator<<(unsignedlonglong value); | (5) | (since C++11) |
basic_ostream& operator<<(double value); | (6) | |
basic_ostream& operator<<(longdouble value); | (7) | |
basic_ostream& operator<<(constvoid* value); | (8) | |
basic_ostream& operator<<(constvolatilevoid* value); | (9) | (since C++23) |
basic_ostream& operator<<(std::nullptr_t); | (10) | (since C++17) |
basic_ostream& operator<<(short value); | (11) | |
basic_ostream& operator<<(int value); | (12) | |
basic_ostream& operator<<(unsignedshort value); | (13) | |
basic_ostream& operator<<(unsignedint value); | (14) | |
basic_ostream& operator<<(float value); | (15) | |
basic_ostream& operator<<(/* extended-floating-point-type */ value); | (16) | (since C++23) |
basic_ostream& operator<<(std::basic_streambuf<CharT, Traits>* sb); | (17) | |
basic_ostream& operator<<( std::ios_base&(*func)(std::ios_base&)); | (18) | |
basic_ostream& operator<<( std::basic_ios<CharT, Traits>&(*func)(std::basic_ios<CharT, Traits>&)); | (19) | |
basic_ostream& operator<<( std::basic_ostream<CharT, Traits>&(*func) | (20) | |
Inserts data into the stream.
badbit.failbit and, iffailbit is set inexceptions(), rethrows the exception.Contents |
| value | - | integer, floating-point, boolean, or pointer value to insert |
| func | - | function to call |
| sb | - | pointer to the stream buffer to read the data from |
There are no overloads for pointers to non-static members, pointers to volatiles,(until C++23) or function pointers (other than the ones with signatures accepted by the(18-20) overloads).
boolalpha was set, in which casetrue is printed).Character and character string arguments (e.g., of typechar orconstchar*) are handled by thenon-member overloads ofoperator<<.
Overload(10) was added by the resolution ofLWG issue 2221, but it is never implemented in any standard library implementation under C++11/14 modes.
#include <iomanip>#include <iostream>#include <sstream> int fun(){return42;} int main(){std::istringstream input("\"Some text.\" ");double f=3.14;bool b=true; std::cout<< fun()// int overload (12)<<' '// non-member overload<<std::boolalpha// function overload (18)<< b// bool overload (1)<<" "// non-member overload<<std::fixed// function overload (18) again<< f// double overload (6)<< input.rdbuf()// streambuf overload<< fun// bool overload (1): there's no overload for int(*)()<<std::endl;// function overload (18) again int x=0;int* p1=&x;volatileint* p2=&x;std::cout<<"p1: "<< p1<<'\n'// `const void*` overload, prints address<<"p2: "<< p2<<'\n';// before C++23 (P1147): bool overload :), because// operator<<(const void*) is not a match, as it discards the `volatile`// qualifier. To fix this, C++23 adds `const volatile void*` overload (9),// that prints the address as expected.}
Possible output:
42 true 3.140000 "Some text." truep1: 0x7ffcea766600p2: 0x7ffcea766600
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| LWG 117 | C++98 | overloads(1-8,11-15) delegated the insertion to num_put::put, but it does not have overloads forshort, unsignedshort,int,unsignedint, andfloat | they are converted before being passed to num_put::put |
| LWG 567 | C++98 | overload(17) behaved as aFormattedOutputFunction because of the resolution ofLWG issue 60 | it behaves as an UnformattedOutputFunction |
| inserts character data or insert into rvalue stream (function template)[edit] | |
| performs stream input and output on strings (function template)[edit] | |
(C++17) | performs stream output on string views (function template)[edit] |
| performs stream input and output of bitsets (function template)[edit] | |
| serializes and deserializes a complex number (function template)[edit] | |
(C++11) | performs stream input and output on pseudo-random number engine (function template)[edit] |
(C++11) | performs stream input and output on pseudo-random number distribution (function template)[edit] |
| inserts a character (public member function)[edit] | |
| inserts blocks of characters (public member function)[edit] | |
(C++17) | converts an integer or floating-point value to a character sequence (function)[edit] |