basic_ostream and character
(1) template< class CharT, class Traits >basic_ostream<CharT, Traits>&
basic_ostream<CharT, Traits>&
basic_ostream<char, Traits>&
basic_ostream<char, Traits>&
basic_ostream<char, Traits>&
basic_ostream and character array
(2) template< class CharT, class Traits >basic_ostream<CharT, Traits>&
basic_ostream<CharT, Traits>&
basic_ostream<char, Traits>&
basic_ostream<char, Traits>&
basic_ostream<char, Traits>&
basic_ostream rvalue
template< class Ostream, class T >
Ostream&& operator<<( Ostream&& os, const T& value );
deleted overloads for basic_ostream and UTF character/array
(4) (since C++20) template< class Traits >basic_ostream<char, Traits>&
basic_ostream<char, Traits>&
basic_ostream<char, Traits>&
basic_ostream<char, Traits>&
basic_ostream<wchar_t, Traits>&
basic_ostream<wchar_t, Traits>&
basic_ostream<wchar_t, Traits>&
basic_ostream<char, Traits>&
basic_ostream<char, Traits>&
basic_ostream<char, Traits>&
basic_ostream<char, Traits>&
basic_ostream<wchar_t, Traits>&
basic_ostream<wchar_t, Traits>&
basic_ostream<wchar_t, Traits>&
Inserts a character or a character string.
Padding is determined as follows:
After insertion,
os.width(0)is called to cancel the effects of
std::setw, if any.
2)Behaves as a
FormattedOutputFunction. After constructing and checking the sentry object, inserts successive characters from the character array whose first element is pointed to by
s.
CharT
matches the type of ch), exactly traits::length(s) characters are inserted.Before insertion, first, all characters are widened using
os.widen(), then padding is determined as follows:
After insertion,
os.width(0)is called to cancel the effects of
std::setw, if any.
If s is a null pointer, the behavior is undefined.
3)Calls the appropriate insertion operator, given an rvalue reference to an output stream object (equivalent to
os << value). This overload participates in overload resolution only if the expression
os << valueis well-formed and
Ostream
is a class type publicly and unambiguously derived from
std::ios_base.
4)Overloads that accept
char16_t,
char32_tetc (or null terminated sequence thereof) are deleted:
std::cout << u'X'is not allowed. Previously, these would print an integer or pointer value.
[edit] Parameters os - output stream to insert data to ch - reference to a character to insert s - pointer to a character string to insert [edit] Return value1,2) os
3) std::move(os)
[edit] NotesBefore LWG issue 1203, code such as (std::ostringstream() << 1.2).str() does not compile.
[edit] Example#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_t const& ch) { return os << static_cast<char>(ch); } int main() { std::cout << "Hello, world" // uses `const char*` overload << '\n'; // uses `char` overload std::ofstream{"test.txt"} << 1.2; // uses rvalue overload std::cout << u8'!' << '\n'; // uses program-defined operator<<(os, char8_t const&) }
Output:
[edit] Defect reportsThe 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 allCharT
does not match the type of ch LWG 1203 C++11 overload for rvalue stream returned
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4