在线文档教程
C++
输入/输出 | Input/output

std::basic_ostream::flush

性病:基本[医]O流::冲水

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...

二次

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

二次

另见

syncsynchronizes with the underlying storage device (public member function of std::basic_istream)
flushflushes the output stream (function template)
endloutputs '\n' and flushes the output stream (function template)

© cppreference.com

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

http://en.cppreference.com/w/cpp/io/basic[医]O流/冲洗