名前空間
変種
操作

「cpp/io/basic istream/swap」の版間の差分

提供: cppreference.com
< cpp‎ | io‎ | basic istream
(r2.7.3) (ロボットによる 追加: de, en, es, fr, it, pt, ru, zh)
 
(1人の利用者による、間の1版が非表示)
1行: 1行:
{{tr_note}}
 
 
{{cpp/io/basic_istream/title | swap}}
 
{{cpp/io/basic_istream/title | swap}}
 
{{cpp/io/basic_istream/navbar}}
 
{{cpp/io/basic_istream/navbar}}
{{ddcl list begin}}
+
{{begin}}
{{ddcl list item |notes={{mark since c++11}} |1=
+
{{| =c++11 |1=
 
protected:
 
protected:
 
void swap(basic_istream& rhs);
 
void swap(basic_istream& rhs);
 
}}
 
}}
{{ddcl list end}}
+
{{end}}
  
{{tr|{{c|basic_ios::swap(rhs)}}は、すべてのデータ{{c|rdbuf()}}を除く基本クラスのメンバ、およびスワップ{{rlpf|gcount}}と{{c|*this}}の間{{tt|rhs}}カウンタの値を交換するために呼び出す。このスワップ機能が保護されています:それは、スワップ可能な入力ストリームクラスのスワップ機能によって呼び出され{{c|std::basic_ifstream}}と{{c|std::basic_istringstream}}、正しく関連付けstreambuffersを交換する方法を知っている.|Calls {{c|basic_ios::swap(rhs)}} to swap all data members of the base class except for {{c|rdbuf()}}, and swaps the values of the {{rlpf|gcount}} counters between {{c|*this}} and {{tt|rhs}}. This swap function is protected: it is called by the swap functions of the swappable input stream classes {{c|std::basic_ifstream}} and {{c|std::basic_istringstream}}, which know how to correctly swap the associated streambuffers.}}
+
{{|{{c|basic_ios::swap(rhs)}} {{c|*this}} {{tt|rhs}} {{|()}} swap protected {{|std::basic_ifstream}} {{|std::basic_istringstream}} swap
  
===パラメータ===
+
======
{{param list begin}}
+
{{begin}}
{{param list item | rhs |{{tr| と交換するために、同じタイプの別のオブジェクトbasic_istream| different basic_istream object of the same type to swap with}}}}
+
{{| rhs | basic_istream }}
{{param list end}}
+
{{end}}
  
 
===例===
 
===例===

2018年6月8日 (金) 16:07時点における最新版

 
 
入出力ライブラリ
入出力マニピュレータ
Cスタイルの入出力
バッファ
(C++98で非推奨)
ストリーム
抽象
ファイル入出力
文字列入出力
配列入出力
(C++98で非推奨)
(C++98で非推奨)
(C++98で非推奨)
同期化出力
エラーカテゴリインタフェース
(C++11)
 
 
protected:
void swap(basic_istream& rhs);
(C++11以上)

rdbuf() を除いた基底クラスのすべてのデータメンバを入れ替えるために basic_ios::swap(rhs) を呼び、また *thisrhs の間で gcount() の値を入れ替えます。 この swap 関数は protected です。 紐付けられているストリームバッファを正しく入れ替える方法を知っているスワップ可能な入力ストリームクラス std::basic_ifstream および std::basic_istringstream の swap 関数によって呼ばれます。

[編集] 引数

rhs - 入れ替える同じ型の別の basic_istream オブジェクト

[編集]

#include <sstream>
#include <iostream>
#include <utility>
int main()
{
    std::istringstream s1("hello");
    std::istringstream s2("bye");
 
    s1.swap(s2); // OK, istringstream has a public swap()
    std::swap(s1, s2); // OK, calls s1.swap(s2)
//  std::cin.swap(s2); // ERROR: swap is a protected member
 
    std::cout << s1.rdbuf();
}

出力:

hello