Namespaces
Variants

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

From cppreference.com
 
 
Input/output library
I/O manipulators
Print functions (C++23)
C-style I/O
Buffers
(deprecated in C++98)(removed in C++26)
Streams
Abstractions
File I/O
String I/O
Array I/O
(deprecated in C++98)(removed in C++26)
(deprecated in C++98)(removed in C++26)
(deprecated in C++98)(removed in C++26)
Synchronized Output
Types
Error category interface
(C++11)
 
 
void emit();
(since C++20)

Emits all buffered output and executes any pending flushes, by calling emit() on the underlying std::basic_syncbuf.

Example

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

Output:

Hello,
World!
Greetings.
Hello, World!

See also

destroys the basic_osyncstream and emits its internal buffer
(public member function) [edit]
atomically transmits the entire internal buffer to the wrapped streambuf
(public member function of std::basic_syncbuf<CharT,Traits,Allocator>) [edit]