std::basic_osyncstream<CharT,Traits,Allocator>::emit
From cppreference.com
< cpp | io | basic osyncstream
C++
Feature test macros (C++20)
Concepts library (C++20)
Metaprogramming library (C++11)
Ranges library (C++20)
Filesystem library (C++17)
Concurrency support library (C++11)
Execution control library (C++26)
Input/output library
Print functions (C++23)
Buffers
(C++23)
(C++98/26*)
(C++20)
Streams
Abstractions
File I/O
String I/O
Array I/O
(C++23)
(C++23)
(C++23)
(C++98/26*)
(C++98/26*)
(C++98/26*)
Synchronized Output
(C++20)
Types
Error category interface
(C++11)
(C++11)
std::basic_osyncstream
Public member functions
(C++20)
(C++20)
(C++20)
basic_osyncstream::emit
(C++20)
void emit();
Emits all buffered output and executes any pending flushes, by calling emit() on the underlying std::basic_syncbuf.
[edit] Parameters
(none)
[edit] Example
Run this code
#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!