| 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) |
| Public member functions | ||||
(C++11) | ||||
basic_stringbuf::swap (C++11) | ||||
(C++20) | ||||
| Protected member functions | ||||
| Non-member functions | ||||
(C++11) | ||||
| Exposition-only member functions | ||||
void swap( basic_stringbuf& rhs); | (since C++11) (until C++20) | |
void swap( basic_stringbuf& rhs)noexcept(/* see below */); | (since C++20) | |
Swaps the state and the contents of*this andrhs.
The behavior is undefined if | (since C++11) |
Contents |
| rhs | - | anotherbasic_stringbuf |
(none)
May throw implementation-defined exceptions. | (since C++11) (until C++20) |
noexcept specification: noexcept(std::allocator_traits<Allocator>::propagate_on_container_swap::value ||std::allocator_traits<Allocator>::is_always_equal::value) | (since C++20) |
This function is called automatically when swappingstd::stringstream objects. It is rarely necessary to call it directly.
#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".
constructs abasic_stringbuf object(public member function)[edit] | |
(C++11) | swaps two string streams (public member function of std::basic_stringstream<CharT,Traits,Allocator>)[edit] |