Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::basic_ostream<CharT,Traits>::operator=

      From cppreference.com
      <cpp‎ |io‎ |basic ostream
       
       
       
       
      protected:
      basic_ostream& operator=(const basic_ostream& rhs)= delete;
      (1)
      protected:
      basic_ostream& operator=( basic_ostream&& rhs);
      (2)(since C++11)
      1) The copy assignment operator is protected, and is deleted. Output streams are notCopyAssignable.
      2) The move assignment operator exchanges all data members of the base class, except forrdbuf(), withrhs, as if by callingswap(*rhs). This move assignment operator is protected: it is only called by the move assignment operators of the derived movable output stream classesstd::basic_ofstream andstd::basic_ostringstream, which know how to correctly move-assign the associated streambuffers.

      [edit]Parameters

      rhs - thebasic_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 derivedstd::cout<< s.str()<<'\n';}

      Output:

      42

      [edit]Defect reports

      The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

      DRApplied toBehavior as publishedCorrect behavior
      LWG 2067C++111. the parameter type of overload(1) wasbasic_ostream&
      2. the parameter type of overload(2) wasconst basic_ostream&&
      1. addedconst
      2. removedconst
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/io/basic_ostream/operator%3D&oldid=156958"

      [8]ページ先頭

      ©2009-2025 Movatter.jp