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); // エラー: swapはprotectedメンバ std::cout << s1.str() << '\n'; }
出力:
hello