std::basic_stringbuf<CharT,Traits,Allocator>::swap - cppreference.com
From cppreference.com
|
(since C++11) (until C++20) |
|
|
|
(since C++20) | |
Swaps the state and the contents of *this and rhs.
|
The behavior is undefined if |
(since C++11) |
Parameters
| rhs | - | another basic_stringbuf
|
Return value
(none)
Exceptions
|
May throw implementation-defined exceptions. |
(since C++11) (until C++20) |
|
noexcept
specification:
|
(since C++20) |
Notes
This function is called automatically when swapping std::stringstream objects. It is rarely necessary to call it directly.
Example
#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"; }
Output:
Before swap: one = "one", two = "two". After swap: one = "two", two = "one".
See also
constructs a basic_stringbuf object (public member function) [edit] | |
| swaps two string streams (public member function of std::basic_stringstream<CharT,Traits,Allocator>) [edit]
|