名前空間
変種
操作

std::basic_ios<CharT,Traits>::copyfmt

提供: cppreference.com
< cpp‎ | io‎ | basic ios
 
 
 
 
basic_ios& copyfmt(const basic_ios& other);

other*this と同じオブジェクトを参照している場合は、効果はありません。 そうでなければ、ストリーム other の状態を *this にコピーします。 これは以下の手順で行われます。

1)register_callback() で登録されたすべてのコールバックを引数として erase_event を渡して呼びます。
2)rdstate()、例外マスク、 rdbuf() を除いたすべてのメンバオブジェクトを other から *this にコピーします。 特に、ロケール、書式フラグ、配列 std::ios_base::iword および std::ios_base::pword の内容 (iword および pword のポインタ自身ではありません)、コールバック、結びつけられているストリームのコピーを作成します。
3)register_callback() で登録されたすべてのコールバックを引数として copyfmt_event を渡して呼びます。
4)exceptions(other.exceptions()) を呼んだかのように例外マスクを other から *this にコピーします。

目次

[編集]引数

other - ソースとして使用する別のストリーム

[編集]戻り値

*this

[編集]ノート

std::ios_base::pword 内のポインタの指すユーザ定義のオブジェクトをディープコピーするためにコールバックを通した2回目のパスを使用できます。

copyfmt() はストリームの状態を保存および復元するために使用することができます。 boost は同じ目的のためのより細粒度な入出力状態保存ライブラリを提供します。

[編集]

std::cout とまったく同様に (書式、 std::cin への tie() など) 動作する ofstream オブジェクト「out」を作成します。

#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
close