Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

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

      From cppreference.com
      <cpp‎ |io‎ |basic ostream
       
       
       
       
      explicit basic_ostream(std::basic_streambuf<CharT, Traits>* sb);
      (1)
      protected:
      basic_ostream(const basic_ostream& rhs)= delete;
      (2)(since C++11)
      protected:
      basic_ostream( basic_ostream&& rhs);
      (3)(since C++11)
      1) Constructs thebasic_ostream object, assigning initial values to the base class by callingbasic_ios::init(sb).
      2) The copy constructor is protected, and is deleted. Output streams are not copyable.
      3) The move constructor usesbasic_ios<CharT, Traits>::move(rhs) to move allbasic_ios members, except for therdbuf(), fromrhs into*this. This move constructor is protected: it is called by the move constructors of movable output stream classesstd::basic_ofstream andstd::basic_ostringstream, which know how to correctly move the associated streambuffer.

      [edit]Parameters

      sb - streambuffer to use as output sequence
      rhs - basic_ostream to initialize from

      [edit]Notes

      Becausebasic_ios::init(sb) setsbadbit whensb is a null pointer, and becausebasic_ostream::sentry does nothing if the stream is already in a failed state, writing to a stream constructed from a null pointersb is a no-op.

      [edit]Example

      Run this code
      #include <iostream>#include <sstream>#include <utility> int main(){// ERROR: copy ctor is deleted//  std::ostream myout(std::cout); // OK: shares buffer with coutstd::ostream myout(std::cout.rdbuf()); // ERROR: move constructor is protected//  std::ostream s2(std::move(std::ostringstream() << 7.1)); // OK: move ctor called through the derived classstd::ostringstream s2(std::ostringstream()<<7.1);    myout<< s2.str()<<'\n'; std::ostream dev_null{nullptr};// see Notes above    dev_null<<"no-op";}

      Output:

      7.1
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/io/basic_ostream/basic_ostream&oldid=158549"

      [8]ページ先頭

      ©2009-2025 Movatter.jp