| 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 | ||||
| Unformatted output | ||||
| Positioning | ||||
| Miscellaneous | ||||
(C++11) | ||||
| Member classes | ||||
| Non-member functions | ||||
operator<<(std::basic_ostream) | ||||
(C++23) | ||||
(C++23) | ||||
(C++23) | ||||
Defined in header <ostream> | ||
basic_ostream and character | ||
| (1) | ||
template<class CharT,class Traits> basic_ostream<CharT, Traits>& | ||
template<class CharT,class Traits> basic_ostream<CharT, Traits>& | ||
template<class Traits> basic_ostream<char, Traits>& | ||
template<class Traits> basic_ostream<char, Traits>& | ||
template<class Traits> basic_ostream<char, Traits>& | ||
basic_ostream and character array | ||
| (2) | ||
template<class CharT,class Traits> basic_ostream<CharT, Traits>& | ||
template<class CharT,class Traits> basic_ostream<CharT, Traits>& | ||
template<class Traits> basic_ostream<char, Traits>& | ||
template<class Traits> basic_ostream<char, Traits>& | ||
template<class Traits> basic_ostream<char, Traits>& | ||
basic_ostream rvalue | ||
template<class Ostream,class T> Ostream&& operator<<( Ostream&& os,const T& value); | (3) | (since C++11) |
deleted overloads for basic_ostream and UTF character/array | ||
| (4) | (since C++20) | |
template<class Traits> basic_ostream<char, Traits>& | ||
template<class Traits> basic_ostream<char, Traits>& | ||
template<class Traits> basic_ostream<char, Traits>& | ||
template<class Traits> basic_ostream<char, Traits>& | ||
template<class Traits> basic_ostream<wchar_t, Traits>& | ||
template<class Traits> basic_ostream<wchar_t, Traits>& | ||
template<class Traits> basic_ostream<wchar_t, Traits>& | ||
template<class Traits> basic_ostream<char, Traits>& | ||
template<class Traits> basic_ostream<char, Traits>& | ||
template<class Traits> basic_ostream<char, Traits>& | ||
template<class Traits> basic_ostream<char, Traits>& | ||
template<class Traits> basic_ostream<wchar_t, Traits>& | ||
template<class Traits> basic_ostream<wchar_t, Traits>& | ||
template<class Traits> basic_ostream<wchar_t, Traits>& | ||
Inserts a character or a character string.
CharT matches the type ofch), exactlytraits::length(s) characters are inserted.Ostream is a class type publicly and unambiguously derived fromstd::ios_base.Contents |
| os | - | output stream to insert data to |
| ch | - | reference to a character to insert |
| s | - | pointer to a character string to insert |
BeforeLWG issue 1203, code such as(std::ostringstream()<<1.2).str() does not compile.
#include <fstream>#include <iostream> void foo(){// error: operator<< (basic_ostream<char, _Traits>&, char8_t) is deleted// std::cout << u8'z' << '\n';} std::ostream& operator<<(std::ostream& os, char8_tconst& ch){return os<<static_cast<char>(ch);} int main(){std::cout<<"Hello, world"// uses `const char*` overload<<'\n';// uses `char` overloadstd::ofstream{"test.txt"}<<1.2;// uses rvalue overload std::cout<< u8'!'<<'\n';// uses program-defined operator<<(os, char8_t const&)}
Output:
Hello, world!
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| LWG 167 | C++98 | the number of characters inserted for all overloads in(2) wastraits::length(s) | updated the numbers for the overloads where CharT does not match the type ofch |
| LWG 1203 | C++11 | overload for rvalue stream returned lvalue reference to the base class | returns rvalue reference to the derived class |
| LWG 2011 | C++98 | padding was determined bystd::num_put::do_put() | determined by the operator itself |
| LWG 2534 | C++11 | overload for rvalue stream was not constrained | constrained |
| inserts formatted data (public member function)[edit] | |
(C++23) | outputsformatted representation of the arguments (function template)[edit] |
| widens characters (public member function of std::basic_ios<CharT,Traits>)[edit] |