[syncstream.osyncstream.members] (original) (raw)

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]

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

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

[Example 1:

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

— _end example_]

[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 (...) { } } — _end example_]

streambuf_type* get_wrapped() const noexcept;

Returns: sb.get_wrapped().

[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_]