Files
2025-10-25 03:02:53 +03:00

2.6 KiB
Raw Permalink Blame History

[syncstream.osyncstream.members]

31 Input/output library [input.output]

31.11 Synchronized output streams [syncstream]

31.11.3 Class template basic_osyncstream [syncstream.osyncstream]

31.11.3.3 Member functions [syncstream.osyncstream.members]

🔗

void emit();

1

#

Effects: Behaves as an unformatted output function ([ostream.unformatted]).

After constructing a sentry object, calls sb.emit().

If that call returns false, calls setstate(ios_base::badbit).

2

#

[Example 1:

A flush on a basic_osyncstream does not flush immediately:{ osyncstream bout(cout); bout << "Hello," << '\n'; // no flush bout.emit(); // characters transferred; cout not flushed bout << "World!" << endl; // flush noted; cout not flushed bout.emit(); // characters transferred; cout flushed bout << "Greetings." << '\n'; // no flush} // characters transferred; cout not flushed

— end example]

3

#

[Example 2:

The function emit() can be used to handle exceptions from operations on the underlying stream.

{ osyncstream bout(cout); bout << "Hello, " << "World!" << '\n'; try { bout.emit(); } catch (...) {// handle exception}} — end example]

🔗

streambuf_type* get_wrapped() const noexcept;

4

#

Returns: sb.get_wrapped().

5

#

[Example 3:

Obtaining the wrapped stream buffer with get_wrapped() allows wrapping it again with an osyncstream.

For example,{ osyncstream bout1(cout); bout1 << "Hello, "; { osyncstream(bout1.get_wrapped()) << "Goodbye, " << "Planet!" << '\n'; } bout1 << "World!" << '\n';} produces the uninterleaved output

Goodbye, Planet!
Hello, World!

— end example]