Namespaces
Variants

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

From cppreference.net
protected :
void swap ( basic_istream & rhs ) ;
(C++11부터)

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

매개변수

rhs - 교환할 동일한 타입의 다른 basic_istream 객체

예제

#include <iostream>
#include <sstream>
#include <utility>
int main()
{
    std::istringstream s1("hello");
    std::istringstream s2("bye");
    s1.swap(s2); // OK, istringstream has a public swap()
    std::swap(s1, s2); // OK, calls s1.swap(s2)
//  std::cin.swap(s2); // ERROR: swap is a protected member
    std::cout << s1.rdbuf() << '\n';
}

출력:

hello