Namespaces
Variants

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

From cppreference.net
protected :
void swap ( basic_ostream & rhs ) ;
(C++11 이후)

basic_ios :: swap ( rhs ) 를 호출하여 기본 클래스의 모든 데이터 멤버를 rdbuf ( ) 를 제외하고 * this rhs 사이에서 교환합니다. 이 swap 함수는 protected로 선언되어 있습니다: 스왑 가능한 출력 스트림 클래스인 std::basic_ofstream std::basic_ostringstream 의 swap 함수들에 의해 호출되며, 이러한 클래스들은 관련된 스트림 버퍼를 올바르게 교환하는 방법을 알고 있습니다.

매개변수

rhs - 교환할 동일한 타입의 basic_ostream

예제

#include <iostream>
#include <sstream>
#include <utility>
int main()
{
    std::ostringstream s1("hello");
    std::ostringstream s2("bye");
    s1.swap(s2); // OK, ostringstream은 public swap()을 가짐
    std::swap(s1, s2); // OK, s1.swap(s2)를 호출
//  std::cout.swap(s2); // ERROR: swap은 protected 멤버임
    std::cout << s1.str() << '\n';
}

출력:

hello