std::basic_osyncstream<CharT,Traits,Allocator>::emit (3) - Linux Manuals

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


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


void emit();

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




// Run this code

  #include <syncstream>
  #include <iostream>
  int main()
      std::osyncstream bout(std::cout);
      std::bout << "Hello," << '\n'; // no flush
      std::bout.emit(); // characters transferred; cout not flushed
      std::bout << "World!" << std::endl; // flush noted; cout not flushed
      std::bout.emit(); // characters transferred; cout flushed
      std::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 {
    } catch (...) {
      // handle exceptions


  Hello, World!

See also

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