std::basic_ostream::flush

来自cppreference.com
< cpp‎ | io‎ | basic ostream

basic_ostream& flush();

Writes uncommitted changes to the underlying output sequence.

If rdbuf() is a null pointer, does nothing

Otherwise, constructs a sentry object which checks the stream for errors and flushes the tie()'d output streams. If the sentry object returns false, does nothing (C++11 起)

Otherwise, calls rdbuf()->pubsync(). If the call returns -1, calls setstate(badbit).

目录

[编辑] 参数

(无)
原文:
(none)
文本通过谷歌翻译机器翻译。
你可以帮忙校正和验证翻译。点击此处查看指示。

[编辑] 返回值

*this

[编辑] 例外

May throw std::ios_base::failure if exceptions()&badbit!=0.

[编辑] 示例

#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()

[编辑] 另请参阅

与底层存储设备同步
(std::basic_istream 的公开成员函数) [编辑]
刷新输出流
原文:
flushes the output stream
文本通过谷歌翻译机器翻译。
你可以帮忙校正和验证翻译。点击此处查看指示。

(函数模板)
输出'\n'并刷新输出流
原文:
outputs '\n' and flushes the output stream
文本通过谷歌翻译机器翻译。
你可以帮忙校正和验证翻译。点击此处查看指示。

(函数模板)