[stream.iterators]

# 24 Iterators library [[iterators]](./#iterators)

## 24.6 Stream iterators [stream.iterators]

### [24.6.1](#general) General [[stream.iterators.general]](stream.iterators.general)

[1](#general-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L6483)

To make it possible for algorithmic templates to work directly with input/output streams, appropriate
iterator-like
class templates
are provided[.](#general-1.sentence-1)

[*Example [1](#general-example-1)*:

partial_sum(istream_iterator<double, char>(cin),
 istream_iterator<double, char>(),
 ostream_iterator<double, char>(cout, "\n")); reads a file containing floating-point numbers fromcin,
and prints the partial sums ontocout[.](#general-1.sentence-2)

â *end example*]

### [24.6.2](#istream.iterator) Class template istream_iterator [[istream.iterator]](istream.iterator)

#### [24.6.2.1](#istream.iterator.general) General [[istream.iterator.general]](istream.iterator.general)

[1](#istream.iterator.general-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L6505)

The class template istream_iterator is an input iterator ([[input.iterators]](input.iterators "24.3.5.3 Input iterators")) that reads successive elements
from the input stream for which it was constructed[.](#istream.iterator.general-1.sentence-1)

namespace std {template<class T, class charT = char, class traits = char_traits<charT>, class Distance = ptrdiff_t>class istream_iterator {public:using iterator_category = input_iterator_tag; using value_type = T; using difference_type = Distance; using pointer = const T*; using reference = const T&; using char_type = charT; using traits_type = traits; using istream_type = basic_istream<charT,traits>; constexpr istream_iterator(); constexpr istream_iterator(default_sentinel_t);
 istream_iterator(istream_type& s); constexpr istream_iterator(const istream_iterator& x) noexcept(*see below*); ~istream_iterator() = default;
 istream_iterator& operator=(const istream_iterator&) = default; const T& operator*() const; const T* operator->() const;
 istream_iterator& operator++();
 istream_iterator operator++(int); friend bool operator==(const istream_iterator& i, default_sentinel_t); private: basic_istream<charT,traits>* in_stream; // *exposition only* T value; // *exposition only*};}

[2](#istream.iterator.general-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L6547)

The type T shall meet the *Cpp17DefaultConstructible*,*Cpp17CopyConstructible*, and *Cpp17CopyAssignable* requirements[.](#istream.iterator.general-2.sentence-1)

#### [24.6.2.2](#istream.iterator.cons) Constructors and destructor [[istream.iterator.cons]](istream.iterator.cons)

[ð](#lib:istream_iterator,constructor)

`constexpr istream_iterator();
constexpr istream_iterator(default_sentinel_t);
`

[1](#istream.iterator.cons-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L6560)

*Effects*: Constructs the end-of-stream iterator, value-initializing value[.](#istream.iterator.cons-1.sentence-1)

[2](#istream.iterator.cons-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L6564)

*Postconditions*: in_stream == nullptr is true[.](#istream.iterator.cons-2.sentence-1)

[3](#istream.iterator.cons-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L6568)

*Remarks*: If the initializer T() in the declaration auto x = T(); is a constant initializer ([[expr.const]](expr.const "7.7 Constant expressions")),
then these constructors are constexpr constructors[.](#istream.iterator.cons-3.sentence-1)

[ð](#lib:istream_iterator,constructor_)

`istream_iterator(istream_type& s);
`

[4](#istream.iterator.cons-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L6582)

*Effects*: Initializes in_stream with addressof(s),
value-initializes value,
and then calls operator++()[.](#istream.iterator.cons-4.sentence-1)

[ð](#lib:istream_iterator,constructor__)

`constexpr istream_iterator(const istream_iterator& x) noexcept(see below);
`

[5](#istream.iterator.cons-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L6596)

*Effects*: Initializes in_stream with x.in_stream and
initializes value with x.value[.](#istream.iterator.cons-5.sentence-1)

[6](#istream.iterator.cons-6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L6601)

*Remarks*: An invocation of this constructor may be used in a core constant expression
if and only if the initialization of value from x.value is a constant subexpression ([[defns.const.subexpr]](defns.const.subexpr "3.15 constant subexpression"))[.](#istream.iterator.cons-6.sentence-1)

The exception specification is equivalent tois_nothrow_copy_constructible_v<T>[.](#istream.iterator.cons-6.sentence-2)

[ð](#lib:istream_iterator,destructor)

`~istream_iterator() = default;
`

[7](#istream.iterator.cons-7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L6616)

*Remarks*: If is_trivially_destructible_v<T> is true,
then this destructor is trivial[.](#istream.iterator.cons-7.sentence-1)

#### [24.6.2.3](#istream.iterator.ops) Operations [[istream.iterator.ops]](istream.iterator.ops)

[ð](#lib:operator*,istream_iterator)

`const T& operator*() const;
`

[1](#istream.iterator.ops-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L6630)

*Preconditions*: in_stream != nullptr is true[.](#istream.iterator.ops-1.sentence-1)

[2](#istream.iterator.ops-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L6634)

*Returns*: value[.](#istream.iterator.ops-2.sentence-1)

[ð](#lib:operator-%3e,istream_iterator)

`const T* operator->() const;
`

[3](#istream.iterator.ops-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L6645)

*Preconditions*: in_stream != nullptr is true[.](#istream.iterator.ops-3.sentence-1)

[4](#istream.iterator.ops-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L6649)

*Returns*: addressof(value)[.](#istream.iterator.ops-4.sentence-1)

[ð](#lib:operator++,istream_iterator)

`istream_iterator& operator++();
`

[5](#istream.iterator.ops-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L6660)

*Preconditions*: in_stream != nullptr is true[.](#istream.iterator.ops-5.sentence-1)

[6](#istream.iterator.ops-6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L6664)

*Effects*: Equivalent to:if (!(*in_stream >> value)) in_stream = nullptr;

[7](#istream.iterator.ops-7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L6672)

*Returns*: *this[.](#istream.iterator.ops-7.sentence-1)

[ð](#lib:operator++,istream_iterator_)

`istream_iterator operator++(int);
`

[8](#istream.iterator.ops-8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L6683)

*Preconditions*: in_stream != nullptr is true[.](#istream.iterator.ops-8.sentence-1)

[9](#istream.iterator.ops-9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L6687)

*Effects*: Equivalent to:istream_iterator tmp = *this;++*this;return tmp;

[ð](#lib:operator==,istream_iterator)

`template<class T, class charT, class traits, class Distance>
  bool operator==(const istream_iterator<T,charT,traits,Distance>& x,
                  const istream_iterator<T,charT,traits,Distance>& y);
`

[10](#istream.iterator.ops-10)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L6705)

*Returns*: x.in_stream == y.in_stream[.](#istream.iterator.ops-10.sentence-1)

[ð](#lib:operator==,istream_iterator_)

`friend bool operator==(const istream_iterator& i, default_sentinel_t);
`

[11](#istream.iterator.ops-11)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L6716)

*Returns*: !i.in_stream[.](#istream.iterator.ops-11.sentence-1)

### [24.6.3](#ostream.iterator) Class template ostream_iterator [[ostream.iterator]](ostream.iterator)

#### [24.6.3.1](#ostream.iterator.general) General [[ostream.iterator.general]](ostream.iterator.general)

[1](#ostream.iterator.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[.](#ostream.iterator.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[.](#ostream.iterator.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](#ostream.iterator.cons.des) Constructors and destructor [[ostream.iterator.cons.des]](ostream.iterator.cons.des)

[ð](#lib:ostream_iterator,constructor)

`ostream_iterator(ostream_type& s);
`

[1](#ostream.iterator.cons.des-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L6779)

*Effects*: Initializes out_stream with addressof(s) anddelim with nullptr[.](#ostream.iterator.cons.des-1.sentence-1)

[ð](#lib:ostream_iterator,constructor_)

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

[2](#ostream.iterator.cons.des-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L6792)

*Effects*: Initializes out_stream with addressof(s) anddelim with delimiter[.](#ostream.iterator.cons.des-2.sentence-1)

#### [24.6.3.3](#ostream.iterator.ops) Operations [[ostream.iterator.ops]](ostream.iterator.ops)

[ð](#lib:operator=,ostream_iterator)

`ostream_iterator& operator=(const T& value);
`

[1](#ostream.iterator.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](#ostream.iterator.ops-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L6823)

*Returns*: *this[.](#ostream.iterator.ops-2.sentence-1)

[ð](#lib:operator++,ostream_iterator)

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

[3](#ostream.iterator.ops-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L6835)

*Returns*: *this[.](#ostream.iterator.ops-3.sentence-1)

### [24.6.4](#istreambuf.iterator) Class template istreambuf_iterator [[istreambuf.iterator]](istreambuf.iterator)

#### [24.6.4.1](#istreambuf.iterator.general) General [[istreambuf.iterator.general]](istreambuf.iterator.general)

[1](#istreambuf.iterator.general-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L6844)

The
class templateistreambuf_iterator defines an [input iterator](input.iterators "24.3.5.3 Input iterators [input.iterators]") that
reads successive*characters* from the streambuf for which it was constructed[.](#istreambuf.iterator.general-1.sentence-1)

operator* provides access to the current input character, if any[.](#istreambuf.iterator.general-1.sentence-2)

Each timeoperator++ is evaluated, the iterator advances to the next input character[.](#istreambuf.iterator.general-1.sentence-3)

If the end of stream is reached (streambuf_type​::​sgetc() returnstraits​::​eof()),
the iterator becomes equal to the[*end-of-stream*](#def:end-of-stream) iterator value[.](#istreambuf.iterator.general-1.sentence-4)

The default constructoristreambuf_iterator() and the constructoristreambuf_iterator(nullptr) both construct an end-of-stream iterator object suitable for use
as an end-of-range[.](#istreambuf.iterator.general-1.sentence-5)

All specializations of istreambuf_iterator shall have a trivial copy
constructor, a constexpr default constructor, and a trivial destructor[.](#istreambuf.iterator.general-1.sentence-6)

[2](#istreambuf.iterator.general-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L6871)

The result ofoperator*() on an end-of-stream iterator is undefined[.](#istreambuf.iterator.general-2.sentence-1)

For any other iterator value achar_type value is returned[.](#istreambuf.iterator.general-2.sentence-2)

It is impossible to assign a character via an input iterator[.](#istreambuf.iterator.general-2.sentence-3)

[ð](#lib:istreambuf_iterator)

namespace std {template<class charT, class traits = char_traits<charT>>class istreambuf_iterator {public:using iterator_category = input_iterator_tag; using value_type = charT; using difference_type = typename traits::off_type; using pointer = *unspecified*; using reference = charT; using char_type = charT; using traits_type = traits; using int_type = typename traits::int_type; using streambuf_type = basic_streambuf<charT,traits>; using istream_type = basic_istream<charT,traits>; // [[istreambuf.iterator.proxy]](#istreambuf.iterator.proxy "24.6.4.2 Class istreambuf_­iterator​::​proxy"), class istreambuf_iterator​::​*proxy*class *proxy*; // *exposition only*constexpr istreambuf_iterator() noexcept; constexpr istreambuf_iterator(default_sentinel_t) noexcept;
 istreambuf_iterator(const istreambuf_iterator&) noexcept = default; ~istreambuf_iterator() = default;
 istreambuf_iterator(istream_type& s) noexcept;
 istreambuf_iterator(streambuf_type* s) noexcept;
 istreambuf_iterator(const *proxy*& p) noexcept;
 istreambuf_iterator& operator=(const istreambuf_iterator&) noexcept = default;
 charT operator*() const;
 istreambuf_iterator& operator++(); *proxy* operator++(int); bool equal(const istreambuf_iterator& b) const; friend bool operator==(const istreambuf_iterator& i, default_sentinel_t s); private: streambuf_type* sbuf_; // *exposition only*};}

#### [24.6.4.2](#istreambuf.iterator.proxy) Class istreambuf_iterator​::​*proxy* [[istreambuf.iterator.proxy]](istreambuf.iterator.proxy)

[1](#istreambuf.iterator.proxy-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L6924)

Classistreambuf_iterator<charT,traits>​::​*proxy* is for exposition only[.](#istreambuf.iterator.proxy-1.sentence-1)

An implementation is permitted to provide equivalent functionality without
providing a class with this name[.](#istreambuf.iterator.proxy-1.sentence-2)

Classistreambuf_iterator<charT, traits>​::​*proxy* provides a temporary
placeholder as the return value of the post-increment operator
(operator++)[.](#istreambuf.iterator.proxy-1.sentence-3)

It keeps the character pointed to by the previous value
of the iterator for some possible future access to get the character[.](#istreambuf.iterator.proxy-1.sentence-4)

[ð](#lib:proxy,istreambuf_iterator)

namespace std {template<class charT, class traits>class istreambuf_iterator<charT, traits>::*proxy* { // *exposition only* charT keep_;
 basic_streambuf<charT,traits>* sbuf_; *proxy*(charT c, basic_streambuf<charT,traits>* sbuf): keep_(c), sbuf_(sbuf) { }public: charT operator*() { return keep_; }};}

#### [24.6.4.3](#istreambuf.iterator.cons) Constructors [[istreambuf.iterator.cons]](istreambuf.iterator.cons)

[1](#istreambuf.iterator.cons-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L6955)

For each istreambuf_iterator constructor in this subclause,
an end-of-stream iterator is constructed if and only if
the exposition-only member sbuf_ is initialized with a null pointer value[.](#istreambuf.iterator.cons-1.sentence-1)

[ð](#lib:istreambuf_iterator,constructor)

`constexpr istreambuf_iterator() noexcept;
constexpr istreambuf_iterator(default_sentinel_t) noexcept;
`

[2](#istreambuf.iterator.cons-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L6968)

*Effects*: Initializes sbuf_ with nullptr[.](#istreambuf.iterator.cons-2.sentence-1)

[ð](#lib:istreambuf_iterator,constructor_)

`istreambuf_iterator(istream_type& s) noexcept;
`

[3](#istreambuf.iterator.cons-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L6979)

*Effects*: Initializes sbuf_ with s.rdbuf()[.](#istreambuf.iterator.cons-3.sentence-1)

[ð](#lib:istreambuf_iterator,constructor__)

`istreambuf_iterator(streambuf_type* s) noexcept;
`

[4](#istreambuf.iterator.cons-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L6990)

*Effects*: Initializes sbuf_ with s[.](#istreambuf.iterator.cons-4.sentence-1)

[ð](#lib:istreambuf_iterator,constructor___)

`istreambuf_iterator(const proxy& p) noexcept;
`

[5](#istreambuf.iterator.cons-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L7001)

*Effects*: Initializes sbuf_ with p.sbuf_[.](#istreambuf.iterator.cons-5.sentence-1)

#### [24.6.4.4](#istreambuf.iterator.ops) Operations [[istreambuf.iterator.ops]](istreambuf.iterator.ops)

[ð](#lib:operator*,istreambuf_iterator)

`charT operator*() const;
`

[1](#istreambuf.iterator.ops-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L7014)

*Returns*: The character obtained via thestreambuf membersbuf_->sgetc()[.](#istreambuf.iterator.ops-1.sentence-1)

[ð](#lib:operator++,istreambuf_iterator)

`istreambuf_iterator& operator++();
`

[2](#istreambuf.iterator.ops-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L7028)

*Effects*: As if by sbuf_->sbumpc()[.](#istreambuf.iterator.ops-2.sentence-1)

[3](#istreambuf.iterator.ops-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L7032)

*Returns*: *this[.](#istreambuf.iterator.ops-3.sentence-1)

[ð](#lib:operator++,istreambuf_iterator_)

`proxy operator++(int);
`

[4](#istreambuf.iterator.ops-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L7043)

*Returns*: *proxy*(sbuf_->sbumpc(), sbuf_)[.](#istreambuf.iterator.ops-4.sentence-1)

[ð](#lib:equal,istreambuf_iterator)

`bool equal(const istreambuf_iterator& b) const;
`

[5](#istreambuf.iterator.ops-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L7054)

*Returns*: true if and only if both iterators are at end-of-stream,
or neither is at end-of-stream, regardless of whatstreambuf object they use[.](#istreambuf.iterator.ops-5.sentence-1)

[ð](#lib:operator==,istreambuf_iterator)

`template<class charT, class traits>
  bool operator==(const istreambuf_iterator<charT,traits>& a,
                  const istreambuf_iterator<charT,traits>& b);
`

[6](#istreambuf.iterator.ops-6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L7071)

*Returns*: a.equal(b)[.](#istreambuf.iterator.ops-6.sentence-1)

[ð](#lib:operator==,istreambuf_iterator_)

`friend bool operator==(const istreambuf_iterator& i, default_sentinel_t s);
`

[7](#istreambuf.iterator.ops-7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L7082)

*Returns*: i.equal(s)[.](#istreambuf.iterator.ops-7.sentence-1)

### [24.6.5](#ostreambuf.iterator) Class template ostreambuf_iterator [[ostreambuf.iterator]](ostreambuf.iterator)

#### [24.6.5.1](#ostreambuf.iterator.general) General [[ostreambuf.iterator.general]](ostreambuf.iterator.general)

[1](#ostreambuf.iterator.general-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L7091)

The class template ostreambuf_iterator writes successive *characters* onto the output stream
from which it was constructed[.](#ostreambuf.iterator.general-1.sentence-1)

[ð](#lib:ostreambuf_iterator)

namespace std {template<class charT, class traits = char_traits<charT>>class ostreambuf_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 streambuf_type = basic_streambuf<charT,traits>; using ostream_type = basic_ostream<charT,traits>;

 ostreambuf_iterator(ostream_type& s) noexcept;
 ostreambuf_iterator(streambuf_type* s) noexcept;
 ostreambuf_iterator& operator=(charT c);

 ostreambuf_iterator& operator*();
 ostreambuf_iterator& operator++();
 ostreambuf_iterator& operator++(int); bool failed() const noexcept; private: streambuf_type* sbuf_; // *exposition only*};}

#### [24.6.5.2](#ostreambuf.iter.cons) Constructors [[ostreambuf.iter.cons]](ostreambuf.iter.cons)

[ð](#lib:ostreambuf_iterator,constructor)

`ostreambuf_iterator(ostream_type& s) noexcept;
`

[1](#ostreambuf.iter.cons-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L7135)

*Preconditions*: s.rdbuf() is not a null pointer[.](#ostreambuf.iter.cons-1.sentence-1)

[2](#ostreambuf.iter.cons-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L7140)

*Effects*: Initializes sbuf_ with s.rdbuf()[.](#ostreambuf.iter.cons-2.sentence-1)

[ð](#lib:ostreambuf_iterator,constructor_)

`ostreambuf_iterator(streambuf_type* s) noexcept;
`

[3](#ostreambuf.iter.cons-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L7151)

*Preconditions*: s is not a null pointer[.](#ostreambuf.iter.cons-3.sentence-1)

[4](#ostreambuf.iter.cons-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L7156)

*Effects*: Initializes sbuf_ with s[.](#ostreambuf.iter.cons-4.sentence-1)

#### [24.6.5.3](#ostreambuf.iter.ops) Operations [[ostreambuf.iter.ops]](ostreambuf.iter.ops)

[ð](#lib:operator=,ostreambuf_iterator)

`ostreambuf_iterator& operator=(charT c);
`

[1](#ostreambuf.iter.ops-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L7169)

*Effects*: Iffailed() yieldsfalse,
callssbuf_->sputc(c);
otherwise has no effect[.](#ostreambuf.iter.ops-1.sentence-1)

[2](#ostreambuf.iter.ops-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L7179)

*Returns*: *this[.](#ostreambuf.iter.ops-2.sentence-1)

[ð](#lib:operator*,ostreambuf_iterator)

`ostreambuf_iterator& operator*();
`

[3](#ostreambuf.iter.ops-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L7190)

*Returns*: *this[.](#ostreambuf.iter.ops-3.sentence-1)

[ð](#lib:operator++,ostreambuf_iterator)

`ostreambuf_iterator& operator++();
ostreambuf_iterator& operator++(int);
`

[4](#ostreambuf.iter.ops-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L7202)

*Returns*: *this[.](#ostreambuf.iter.ops-4.sentence-1)

[ð](#lib:failed,ostreambuf_iterator)

`bool failed() const noexcept;
`

[5](#ostreambuf.iter.ops-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L7213)

*Returns*: true if in any prior use of memberoperator=,
the call tosbuf_->sputc() returnedtraits​::​eof();
orfalse otherwise[.](#ostreambuf.iter.ops-5.sentence-1)
