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'; // no flush bout.emit(); // characters transferred; cout not flushed bout << "World!" << std::endl; // flush noted; cout not flushed bout.emit(); // characters transferred; cout flushed bout << "Greetings." << '\n'; // no flush } // destructor calls emit(): characters transferred; cout not flushed // emit can be used for local exception-handling on the wrapped stream std::osyncstream bout(std::cout); bout << "Hello, " << "World!" << '\n'; try { bout.emit(); } catch (...) { // handle exceptions } }
输出
Hello, World! Greetings. Hello, World!
[编辑] 另请参见
销毁 basic_osyncstream 并发出其内部缓冲区(公有成员函数) | |
将整个内部缓冲区原子地传输到包装的 streambuf ( std::basic_syncbuf<CharT,Traits,Allocator> 的公有成员函数) |