24 Iterators library [iterators]

24.6 Stream iterators [stream.iterators]

24.6.2 Class template ostream_iterator [ostream.iterator]

ostream_iterator writes (using operator<<) successive elements onto the output stream from which it was constructed. If it was constructed with charT* as a constructor argument, this string, called a delimiter string, is written to the stream after every T is written. It is not possible to get a value out of the output iterator. Its only use is as an output iterator in situations like

while (first != last)
  *result++ = *first++;

ostream_iterator is defined as:

namespace std {
  template <class T, class charT = char, class traits = char_traits<charT> >
  class ostream_iterator:
    public iterator<output_iterator_tag, void, void, void, void> {
  public:
    typedef charT char_type;
    typedef traits traits_type;
    typedef basic_ostream<charT,traits> ostream_type;
    ostream_iterator(ostream_type& s);
    ostream_iterator(ostream_type& s, const charT* delimiter);
    ostream_iterator(const ostream_iterator<T,charT,traits>& x);
   ~ostream_iterator();
    ostream_iterator<T,charT,traits>& operator=(const T& value);

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

24.6.2.1 ostream_iterator constructors and destructor [ostream.iterator.cons.des]

ostream_iterator(ostream_type& s);

Effects: Initializes out_stream with &s and delim with null.

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

Effects: Initializes out_stream with &s and delim with delimiter.

ostream_iterator(const ostream_iterator& x);

Effects: Constructs a copy of x.

~ostream_iterator();

Effects: The iterator is destroyed.

24.6.2.2 ostream_iterator operations [ostream.iterator.ops]

ostream_iterator& operator=(const T& value);

Effects:

*out_stream << value;
if (delim != 0)
  *out_stream << delim;
return *this;

ostream_iterator& operator*();

Returns: *this.

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

Returns: *this.