std::basic_ostream<CharT,Traits>::operator=
From cppreference.com
< cpp | io | basic ostream
C++
Feature test macros (C++20)
Concepts library (C++20)
Metaprogramming library (C++11)
Ranges library (C++20)
Filesystem library (C++17)
Concurrency support library (C++11)
Execution control library (C++26)
Input/output library
Print functions (C++23)
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)
std::basic_ostream
Member functions
Formatted output
Unformatted output
Positioning
Miscellaneous
Member classes
Non-member functions
Global objects
basic_ostream::operator=
(C++11)
(C++11)
(C++23)
(C++23)
(C++23)
(C++23)
protected:
basic_ostream& operator=( const basic_ostream& rhs ) = delete;
(1)
basic_ostream& operator=( const basic_ostream& rhs ) = delete;
protected:
basic_ostream& operator=( basic_ostream&& rhs );
(2)
(since C++11)
basic_ostream& operator=( basic_ostream&& rhs );
1) The copy assignment operator is protected, and is deleted. Output streams are not CopyAssignable.
2) The move assignment operator exchanges all data members of the base class, except for rdbuf(), with rhs, as if by calling swap(*rhs). This move assignment operator is protected: it is only called by the move assignment operators of the derived movable output stream classes std::basic_ofstream and std::basic_ostringstream , which know how to correctly move-assign the associated streambuffers.
[edit] Parameters
rhs
-
the
basic_ostream
object from which to assign to *this
[edit] Example
Run this code
#include <iostream> #include <sstream> #include <utility> int main() { std::ostringstream s; // std::cout = s; // ERROR: copy assignment operator is deleted // std::cout = std::move(s); // ERROR: move assignment operator is protected s = std::move(std::ostringstream () << 42); // OK, moved through derived std::cout << s.str() << '\n'; }
Output:
42
[edit] Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR | Applied to | Behavior as published | Correct behavior |
---|---|---|---|
LWG 2067 | C++11 | 1. the parameter type of overload (1) was basic_ostream& 2. the parameter type of overload (2) was const basic_ostream&& |
1. added const 2. removed const |