std::basic_ostream<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 output | ||||
| Unformatted output | ||||
| Positioning | ||||
| Miscellaneous | ||||
|
basic_ostream::swap
(C++11)
|
||||
| Member classes | ||||
| Non-member functions | ||||
|
(C++23)
|
||||
|
(C++23)
|
||||
|
(C++23)
|
||||
|
(C++23)
|
||||
|
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