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

79 lines
2.6 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[syncstream.osyncstream.members]
# 31 Input/output library [[input.output]](./#input.output)
## 31.11 Synchronized output streams [[syncstream]](syncstream#osyncstream.members)
### 31.11.3 Class template basic_osyncstream [[syncstream.osyncstream]](syncstream.osyncstream#members)
#### 31.11.3.3 Member functions [syncstream.osyncstream.members]
[🔗](#lib:set_emit_on_sync,basic_osyncstream)
`void emit();
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L13038)
*Effects*: Behaves as an unformatted output function ([[ostream.unformatted]](ostream.unformatted "31.7.6.4Unformatted output functions"))[.](#1.sentence-1)
After constructing a sentry object, calls *sb*.emit()[.](#1.sentence-2)
If that call returns false,
calls setstate(ios_base::badbit)[.](#1.sentence-3)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L13045)
[*Example [1](#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](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L13060)
[*Example [2](#example-2)*:
The function emit() can be used to
handle exceptions from operations on the underlying stream[.](#3.sentence-1)
{ osyncstream bout(cout);
bout << "Hello, " << "World!" << '\n'; try { bout.emit(); } catch (...) {// handle exception}} — *end example*]
[🔗](#lib:set_emit_on_sync,basic_osyncstream_)
`streambuf_type* get_wrapped() const noexcept;
`
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L13084)
*Returns*: *sb*.get_wrapped()[.](#4.sentence-1)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L13088)
[*Example [3](#example-3)*:
Obtaining the wrapped stream buffer with get_wrapped() allows wrapping it again with an osyncstream[.](#5.sentence-1)
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*]