Namespaces
Variants

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

From cppreference.net
explicit basic_ostream ( std:: basic_streambuf < CharT, Traits > * sb ) ;
(1)
protected :
basic_ostream ( const basic_ostream & rhs ) = delete ;
(2) (C++11 이후)
protected :
basic_ostream ( basic_ostream && rhs ) ;
(3) (C++11 이후)
1) basic_ostream 객체를 생성하며, 기본 클래스에 초기값을 할당하기 위해 basic_ios::init(sb) 를 호출합니다.
2) 복사 생성자는 protected로 선언되었으며 삭제되었습니다. 출력 스트림은 복사할 수 없습니다.
3) 이동 생성자는 basic_ios < CharT, Traits > :: move ( rhs ) 를 사용하여 rdbuf() 를 제외한 모든 basic_ios 멤버들을 rhs 에서 * this 로 이동시킵니다. 이 이동 생성자는 protected로 선언되어 있습니다: 이는 이동 가능한 출력 스트림 클래스인 std::basic_ofstream std::basic_ostringstream 의 이동 생성자들에 의해 호출되며, 이러한 클래스들은 관련된 스트림 버퍼를 올바르게 이동시키는 방법을 알고 있습니다.

매개변수

sb - 출력 시퀀스로 사용할 streambuffer
rhs - 초기화에 사용할 basic_ostream

참고 사항

basic_ios::init(sb) sb 가 널 포인터일 때 badbit 를 설정하고, basic_ostream::sentry 가 스트림이 이미 실패 상태일 경우 아무 작업도 수행하지 않기 때문에, 널 포인터 sb 로부터 생성된 스트림에 쓰기는 no-op입니다.

예제

#include <iostream>
#include <sstream>
#include <utility>
int main()
{
    // ERROR: 복사 생성자가 삭제됨
//  std::ostream myout(std::cout);
    // OK: cout과 버퍼를 공유함
    std::ostream myout(std::cout.rdbuf());
    // ERROR: 이동 생성자가 protected로 선언됨
//  std::ostream s2(std::move(std::ostringstream() << 7.1));
    // OK: 파생 클래스를 통해 이동 생성자 호출
    std::ostringstream s2(std::ostringstream() << 7.1);
    myout << s2.str() << '\n';
    std::ostream dev_null{nullptr}; // 위의 주석 참조
    dev_null << "no-op";
}

출력:

7.1