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

92 lines
3.2 KiB
Markdown

[ostream.iterator]
# 24 Iterators library [[iterators]](./#iterators)
## 24.6 Stream iterators [[stream.iterators]](stream.iterators#ostream.iterator)
### 24.6.3 Class template ostream_iterator [ostream.iterator]
#### [24.6.3.1](#general) General [[ostream.iterator.general]](ostream.iterator.general)
[1](#general-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L6725)
ostream_iterator writes (usingoperator<<)
successive elements onto the output stream from which it was constructed[.](#general-1.sentence-1)
If it was constructed withcharT* as a constructor argument, this string, called a[*delimiter string*](#def:delimiter_string),
is written to the stream after everyT is written[.](#general-1.sentence-2)
namespace std {template<class T, class charT = char, class traits = char_traits<charT>>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 only*const charT* delim; // *exposition only*};}
#### [24.6.3.2](#cons.des) Constructors and destructor [[ostream.iterator.cons.des]](ostream.iterator.cons.des)
[🔗](#lib:ostream_iterator,constructor)
`ostream_iterator(ostream_type& s);
`
[1](#cons.des-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L6779)
*Effects*: Initializes out_stream with addressof(s) anddelim with nullptr[.](#cons.des-1.sentence-1)
[🔗](#lib:ostream_iterator,constructor_)
`ostream_iterator(ostream_type& s, const charT* delimiter);
`
[2](#cons.des-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L6792)
*Effects*: Initializes out_stream with addressof(s) anddelim with delimiter[.](#cons.des-2.sentence-1)
#### [24.6.3.3](#ops) Operations [[ostream.iterator.ops]](ostream.iterator.ops)
[🔗](#lib:operator=,ostream_iterator)
`ostream_iterator& operator=(const T& value);
`
[1](#ops-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L6806)
*Effects*: As if by:*out_stream << value;if (delim)*out_stream << delim;return *this;
[🔗](#lib:operator*,ostream_iterator)
`ostream_iterator& operator*();
`
[2](#ops-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L6823)
*Returns*: *this[.](#ops-2.sentence-1)
[🔗](#lib:operator++,ostream_iterator)
`ostream_iterator& operator++();
ostream_iterator& operator++(int);
`
[3](#ops-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L6835)
*Returns*: *this[.](#ops-3.sentence-1)