名前空間
変種
操作

std::basic_istream<CharT,Traits>::swap

提供: cppreference.com
< cpp‎ | io‎ | basic istream
2013年7月2日 (火) 13:19時点におけるP12bot (トーク | 投稿記録)による版

 
 
入出力ライブラリ
入出力マニピュレータ
Cスタイルの入出力
バッファ
(C++98で非推奨)
ストリーム
抽象
ファイル入出力
文字列入出力
配列入出力
(C++98で非推奨)
(C++98で非推奨)
(C++98で非推奨)
同期化出力
エラーカテゴリインタフェース
(C++11)
 
 
protected:
void swap(basic_istream& rhs);
(C++11以上)
basic_ios::swap(rhs)は、すべてのデータrdbuf()を除く基本クラスのメンバ、およびスワップgcount()*thisの間rhsカウンタの値を交換するために呼び出す。このスワップ機能が保護されています:それは、スワップ可能な入力ストリームクラスのスワップ機能によって呼び出されstd::basic_ifstreamstd::basic_istringstream、正しく関連付けstreambuffersを交換する方法を知っている.
Original:
Calls basic_ios::swap(rhs) to swap all data members of the base class except for rdbuf(), and swaps the values of the gcount() counters between *this and rhs. This swap function is protected: it is called by the swap functions of the swappable input stream classes std::basic_ifstream and std::basic_istringstream, which know how to correctly swap the associated streambuffers.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

パラメータ

rhs -
と交換するために、同じタイプの別のオブジェクトbasic_istream
Original:
different basic_istream object of the same type to swap with
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

#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