std::basic_osyncstream<CharT,Traits,Allocator>::emit
来自cppreference.com
< cpp | io | basic osyncstream
void emit(); |
||
通过在底层 std::basic_syncbuf 上调用 emit(),发出所有缓冲的输出并执行任何未决的冲洗。
参数
(无)
示例
运行此代码
#include <iostream> #include <syncstream> int main() { { std::osyncstream bout(std::cout); bout << "Hello," << '\n'; // 不冲洗 bout.emit(); // 传输字符;不冲洗 cout bout << "World!" << std::endl; // 标记冲洗;不冲洗 cout bout.emit(); // 传输字符;冲洗 cout bout << "Greetings." << '\n'; // 不冲洗 } // 析构函数调用 emit() :传输字符;不冲洗 cout // emit 能用于被包装流上的局部异常处理 std::osyncstream bout(std::cout); bout << "Hello, " << "World!" << '\n'; try { bout.emit(); } catch (...) { // 处理异常 } }
输出:
Hello, World! Greetings. Hello, World!
参阅
销毁 basic_osyncstream 并发出它的内部缓冲区 (公开成员函数) | |
原子地传输整个内部缓冲区给被包装的 streambuf ( std::basic_syncbuf<CharT,Traits,Allocator> 的公开成员函数) |