std::basic_istream<CharT,Traits>:: swap
| I/O manipulators | ||||
| Print functions (C++23) | ||||
| C-style I/O | ||||
| Buffers | ||||
|
(C++23)
|
||||
|
(
C++98/26*
)
|
||||
|
(C++20)
|
||||
| Streams | ||||
| Abstractions | ||||
| File I/O | ||||
| String I/O | ||||
| Array I/O | ||||
|
(C++23)
|
||||
|
(C++23)
|
||||
|
(C++23)
|
||||
|
(
C++98/26*
)
|
||||
|
(
C++98/26*
)
|
||||
|
(
C++98/26*
)
|
||||
| Synchronized Output | ||||
|
(C++20)
|
||||
| Types | ||||
| Error category interface | ||||
|
(C++11)
|
||||
|
(C++11)
|
| Global objects | ||||
| Member functions | ||||
|
(C++11)
|
||||
| Formatted input | ||||
| Unformatted input | ||||
| Positioning | ||||
| Miscellaneous | ||||
|
basic_istream::swap
(C++11)
|
||||
| Member classes | ||||
| Non-member functions | ||||
|
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