首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::basic_ostream::flush

basic_ostream& flush();

?

?

将未提交的更改写入基础输出序列。

如果rdbuf%28%29是空指针,则不执行任何操作。

否则,作为UnformattedOutputFunction%28自C++11%29。在构造和检查哨兵对象之后,调用rdbuf()->pubsync().如果呼叫返回-1,电话setstate(badbit)...

参数

%280%29

返回值

*this...

例外

可抛std::ios_base::failure如果exceptions()&badbit!=0...

二次

代码语言:javascript
复制
#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();
}

二次

产出:

二次

代码语言:javascript
复制
Output from main
Output from thread.....thread calls flush()

二次

另见

sync

synchronizes with the underlying storage device (public member function of std::basic_istream)

flush

flushes the output stream (function template)

endl

outputs '\n' and flushes the output stream (function template)

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com