std::basic_ios<CharT,Traits>::copyfmt
提供: cppreference.com
basic_ios& copyfmt(const basic_ios& other); | ||
other が *this と同じオブジェクトを参照している場合は、効果はありません。 そうでなければ、ストリーム other
の状態を *this にコピーします。 これは以下の手順で行われます。
2)rdstate()、例外マスク、 rdbuf() を除いたすべてのメンバオブジェクトを
other
から *this にコピーします。 特に、ロケール、書式フラグ、配列 std::ios_base::iword および std::ios_base::pword の内容 (iword
および pword
のポインタ自身ではありません)、コールバック、結びつけられているストリームのコピーを作成します。4)exceptions(other.exceptions()) を呼んだかのように例外マスクを
other
から *this にコピーします。目次 |
[編集]引数
other | - | ソースとして使用する別のストリーム |
[編集]戻り値
*this。
[編集]ノート
std::ios_base::pword 内のポインタの指すユーザ定義のオブジェクトをディープコピーするためにコールバックを通した2回目のパスを使用できます。
copyfmt()
はストリームの状態を保存および復元するために使用することができます。 boost は同じ目的のためのより細粒度な入出力状態保存ライブラリを提供します。
[編集]例
std::cout とまったく同様に (書式、 std::cin への tie() など) 動作する ofstream オブジェクト「out」を作成します。
Run this code
#include <iostream>#include <fstream> int main(){std::ofstream out; out.copyfmt(std::cout);// copy everything except rdstate and rdbuf out.clear(std::cout.rdstate());// copy rdstate out.basic_ios<char>::rdbuf(std::cout.rdbuf());// share the buffer out <<"Hello, world\n";}
出力:
Hello, world