Files
cppdraft_translate/cppdraft/syncstream/osyncstream/overview.md
2025-10-25 03:02:53 +03:00

3.0 KiB

[syncstream.osyncstream.overview]

31 Input/output library [input.output]

31.11 Synchronized output streams [syncstream]

31.11.3 Class template basic_osyncstream [syncstream.osyncstream]

31.11.3.1 Overview [syncstream.osyncstream.overview]

🔗

namespace std {template<class charT, class traits = char_traits, class Allocator = allocator>class basic_osyncstream : public basic_ostream<charT, traits> {public:using char_type = charT; using int_type = typename traits::int_type; using pos_type = typename traits::pos_type; using off_type = typename traits::off_type; using traits_type = traits; using allocator_type = Allocator; using streambuf_type = basic_streambuf<charT, traits>; using syncbuf_type = basic_syncbuf<charT, traits, Allocator>; // [syncstream.osyncstream.cons], construction and destruction basic_osyncstream(streambuf_type*, const Allocator&); explicit basic_osyncstream(streambuf_type* obuf): basic_osyncstream(obuf, Allocator()) {} basic_osyncstream(basic_ostream<charT, traits>& os, const Allocator& allocator): basic_osyncstream(os.rdbuf(), allocator) {}explicit basic_osyncstream(basic_ostream<charT, traits>& os): basic_osyncstream(os, Allocator()) {} basic_osyncstream(basic_osyncstream&&) noexcept; ~basic_osyncstream(); // assignment basic_osyncstream& operator=(basic_osyncstream&&); // [syncstream.osyncstream.members], member functionsvoid emit(); streambuf_type* get_wrapped() const noexcept; syncbuf_type* rdbuf() const noexcept { return const_cast<syncbuf_type*>(addressof(sb)); }private: syncbuf_type sb; // exposition only};}

1

#

Allocator shall meet the Cpp17Allocator requirements ([allocator.requirements.general]).

2

#

[Example 1:

A named variable can be used within a block statement for streaming.

{ osyncstream bout(cout); bout << "Hello, "; bout << "World!"; bout << endl; // flush is noted bout << "and more!\n";} // characters are transferred and cout is flushed — end example]

3

#

[Example 2:

A temporary object can be used for streaming within a single statement.

osyncstream(cout) << "Hello, " << "World!" << '\n';

In this example, cout is not flushed.

— end example]