std::basic_stringbuf<CharT,Traits,Allocator>:: swap
From cppreference.net
<
cpp
|
io
|
basic stringbuf
|
void
swap
(
basic_stringbuf
&
rhs
)
;
|
(C++11부터)
(C++20까지) |
|
|
void
swap
(
basic_stringbuf
&
rhs
)
noexcept
(
/* 아래 참조 */
)
;
|
(C++20부터) | |
* this 와 rhs 의 상태와 내용을 교환합니다.
|
|
(since C++11) |
목차 |
매개변수
| rhs | - |
another
basic_stringbuf
|
반환값
(없음)
예외
|
구현 정의 예외를 throw할 수 있습니다. |
(since C++11)
(until C++20) |
|
noexcept
명세:
noexcept
(
std::
allocator_traits
<
Allocator
>
::
propagate_on_container_swap
::
value
|| std:: allocator_traits < Allocator > :: is_always_equal :: value ) |
(since C++20) |
참고 사항
이 함수는 std::stringstream 객체를 교환할 때 자동으로 호출됩니다. 직접 호출해야 하는 경우는 거의 없습니다.
예제
이 코드 실행
#include <iomanip> #include <iostream> #include <sstream> #include <string> int main() { std::istringstream one("one"); std::ostringstream two("two"); std::cout << "Before swap: one = " << std::quoted(one.str()) << ", two = " << std::quoted(two.str()) << ".\n"; one.rdbuf()->swap(*two.rdbuf()); std::cout << "After swap: one = " << std::quoted(one.str()) << ", two = " << std::quoted(two.str()) << ".\n"; }
출력:
Before swap: one = "one", two = "two". After swap: one = "two", two = "one".
참고 항목
basic_stringbuf
객체를 생성합니다
(public member function) |
|
|
(C++11)
|
두 개의 string stream을 교환합니다
(
std::basic_stringstream<CharT,Traits,Allocator>
의
public member function)
|