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

> C++ Atlas: `cppatlas.com/w/cpp/io/basic_osyncstream/emit` | Source: https://en.cppreference.com/w/cpp/io/basic_osyncstream/emit | Domain: Input/output

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

## Official Specification Summary (cppreference)

```cpp
void emit();
```

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

### Parameters

(none)

### Example

```cpp
#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:

```text
Hello,
World!
Greetings.
Hello, World!
```

### See also

- [(destructor)](https://en.cppreference.com/w/cpp/io/basic_osyncstream/~basic_osyncstream): destroys the `basic_osyncstream` and emits its internal buffer (public member function)
- [`emit`](https://en.cppreference.com/w/cpp/io/basic_syncbuf/emit): atomically transmits the entire internal buffer to the wrapped streambuf (public member function of `std::basic_syncbuf<CharT,Traits,Allocator>`)

---
Attribution: content from https://en.cppreference.com/w/cpp/io/basic_osyncstream/emit (cppreference.com), licensed under CC-BY-SA 3.0 and GFDL. Modified: converted to markdown, study notes added. Offline snapshot of 9 February 2025.