名前空間
変種
操作

std::basic_stringbuf<CharT,Traits,Allocator>::swap

From cppreference.com
< cpp‎ | io‎ | basic stringbuf
 
 
 
 
void swap( basic_stringbuf& rhs );
(C++11以降)
(C++20まで)
void swap( basic_stringbuf& rhs ) noexcept(/* 以下参照 */);
(C++20以降)

*thisrhs の状態と内容を交換します。

Allocator が swap で伝播せず、かつ *thisother のアロケータが等しくない場合、動作は未定義です。

(C++11以降)

目次

[編集] パラメータ

rhs - 別の basic_stringbuf

[編集] 返り値

(なし)

[編集] 例外

実装定義の例外をスローする場合があります。

(C++11以降)
(C++20まで)
noexcept 指定:  
noexcept(std::allocator_traits<Allocator>::propagate_on_container_swap::value
|| std::allocator_traits<Allocator>::is_always_equal::value)
(C++20以降)

[編集] 注記

この関数は、std::stringstream オブジェクトを swap する際に自動的に呼び出されます。直接呼び出す必要はほとんどありません。

[編集]

#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 メンバ関数) [編集]
(C++11)
2つの文字列ストリームをスワップする
(std::basic_stringstream<CharT,Traits,Allocator> の public メンバ関数) [編集]
English 日本語 中文(简体) 中文(繁體)