命名空间
变体
操作

std::basic_osyncstream<CharT,Traits,Allocator>::emit

来自 cppreference.cn
void emit();

通过在底层的 emit() 上调用 std::basic_syncbuf,发出所有缓冲的输出并执行任何挂起的刷新。

[edit] 参数

(无)

[edit] 示例

#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!

[edit] 参见

销毁 basic_osyncstream 并发出其内部缓冲区
(公共成员函数) [编辑]
原子性地将整个内部缓冲区传输到包装的 streambuf
std::basic_syncbuf<CharT,Traits,Allocator> 的公共成员函数) [编辑]