Files
cppdraft_translate/cppdraft/ostream/iterator.md
2025-10-25 03:02:53 +03:00

3.2 KiB

[ostream.iterator]

24 Iterators library [iterators]

24.6 Stream iterators [stream.iterators]

24.6.3 Class template ostream_iterator [ostream.iterator]

24.6.3.1 General [ostream.iterator.general]

1

#

ostream_iterator writes (usingoperator<<) successive elements onto the output stream from which it was constructed.

If it was constructed withcharT* as a constructor argument, this string, called adelimiter string, is written to the stream after everyT is written.

namespace std {template<class T, class charT = char, class traits = char_traits>class ostream_iterator {public:using iterator_category = output_iterator_tag; using value_type = void; using difference_type = ptrdiff_t; using pointer = void; using reference = void; using char_type = charT; using traits_type = traits; using ostream_type = basic_ostream<charT,traits>;

ostream_iterator(ostream_type& s); ostream_iterator(ostream_type& s, const charT* delimiter); ostream_iterator(const ostream_iterator& x); ~ostream_iterator(); ostream_iterator& operator=(const ostream_iterator&) = default; ostream_iterator& operator=(const T& value);

ostream_iterator& operator*(); ostream_iterator& operator++(); ostream_iterator& operator++(int); private: basic_ostream<charT,traits>* out_stream; // exposition onlyconst charT* delim; // exposition only};}

24.6.3.2 Constructors and destructor [ostream.iterator.cons.des]

🔗

ostream_iterator(ostream_type& s);

1

#

Effects: Initializes out_stream with addressof(s) anddelim with nullptr.

🔗

ostream_iterator(ostream_type& s, const charT* delimiter);

2

#

Effects: Initializes out_stream with addressof(s) anddelim with delimiter.

24.6.3.3 Operations [ostream.iterator.ops]

🔗

ostream_iterator& operator=(const T& value);

1

#

Effects: As if by:*out_stream << value;if (delim)*out_stream << delim;return *this;

🔗

ostream_iterator& operator*();

2

#

Returns: *this.

🔗

ostream_iterator& operator++(); ostream_iterator& operator++(int);

3

#

Returns: *this.