std:: unitbuf, std:: nounitbuf
|
定義済みヘッダー
<ios>
|
||
|
std::
ios_base
&
unitbuf
(
std::
ios_base
&
str
)
;
|
(1) | |
|
std::
ios_base
&
nounitbuf
(
std::
ios_base
&
str
)
;
|
(2) | |
出力操作の後に出力ストリームの自動フラッシュを有効または無効にします。入力には影響しません。
これはI/Oマニピュレータであり、
out
<<
std
::
unitbuf
のような式で呼び出すことができます(
out
が
std::basic_ostream
型の場合)。または、
in
>>
std
::
unitbuf
のような式で呼び出すこともできます(
in
が
std::basic_istream
型の場合)。
目次 |
注記
フラッシュは std::basic_ostream::sentry オブジェクトのデストラクタで実行され、これは str. rdbuf ( ) - > pubsync ( ) を呼び出します( str. flags ( ) & std:: ios_base :: unitbuf が true の場合)。
標準出力オブジェクト
std::cerr
および
std::wcerr
は、デフォルトで
unitbuf
ビットが設定されています。
パラメータ
| str | - | I/Oストリームへの参照 |
戻り値
str (操作後のストリームへの参照)。
例
std::unitbufまたは他の明示的なフラッシュがない場合、出力は同じですが、リアルタイムでは表示されません。
#include <chrono> #include <iostream> template<typename Diff> void log_progress(Diff d) { std::cout << std::chrono::duration_cast<std::chrono::milliseconds>(d) << " ... "; } int main() { volatile int sink = 0; std::cout << std::unitbuf; // enable automatic flushing const auto start = std::chrono::high_resolution_clock::now(); for (int j = 0; j < 5; ++j) { for (int n = 0; n < 10000; ++n) for (int m = 0; m < 20000; ++m) sink += m * n; // do some work log_progress(std::chrono::high_resolution_clock::now() - start); } std::cout << '\n'; }
出力:
571ms ... 1146ms ... 1722ms ... 2294ms ... 2865ms ...
関連項目
|
出力ストリームをフラッシュする
(関数テンプレート) |
|
|
'
\n
'
を出力し、出力ストリームをフラッシュする
(関数テンプレート) |