名前空間
変種
操作

std::basic_ostream<CharT,Traits>::flush

提供: cppreference.com
< cpp‎ | io‎ | basic ostream
 
 
入出力ライブラリ
入出力マニピュレータ
Cスタイルの入出力
バッファ
(C++98で非推奨)
ストリーム
抽象
ファイル入出力
文字列入出力
配列入出力
(C++98で非推奨)
(C++98で非推奨)
(C++98で非推奨)
同期化出力
エラーカテゴリインタフェース
(C++11)
 
 
basic_ostream& flush();

まだコミットしていない変更をベースとなる出力シーケンスに書き込みます。

rdbuf() がヌルポインタの場合は何もしません。

そうでなければ、 UnformattedOutputFunction として動作します (C++11以上)。 sentry オブジェクトの構築および確認の後、 rdbuf()->pubsync() を呼びます。 呼び出しが -1 を返した場合は setstate(badbit) を呼びます。

目次

[編集] 引数

(なし)

[編集] 戻り値

*this

[編集] 例外

exceptions()&badbit!=0 の場合は std::ios_base::failure を投げる可能性があります。

[編集]

#include <thread>
#include <iostream>
#include <chrono>
void f()
{
    std::cout << "Output from thread...";
    std::this_thread::sleep_for(std::chrono::seconds(2));
    std::cout << "...thread calls flush()\n";
    std::cout.flush();
}
 
int main()
{
    std::thread t1(f);
    std::this_thread::sleep_for(std::chrono::seconds(1));
    std::clog << "Output from main\n";
    t1.join();
}

出力:

Output from main
Output from thread.....thread calls flush()

[編集] 関連項目

sync() を呼びます
(std::basic_streambuf<CharT,Traits>のパブリックメンバ関数) [edit]
[仮想]
バッファを紐付けられている文字シーケンスと同期します
(std::basic_streambuf<CharT,Traits>の仮想プロテクテッドメンバ関数) [edit]
出力ストリームをフラッシュします
(関数テンプレート) [edit]
'\n' を出力して出力ストリームをフラッシュします
(関数テンプレート) [edit]
ベースとなるストレージデバイスと同期します
(std::basic_istream<CharT,Traits>のパブリックメンバ関数) [edit]