Name

ostream_iterator class template — Output iterator to write items to an ostream

Synopsis

template <typename T, typename charT = char,  
          typename 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);
};

The ostream_iterator class template wraps an output iterator around an output stream (instance of basic_ostream), making the stream appear to be a sequence of items, each of type T. For example, suppose you have a vector of data. You can print the data, one number per line, by using an ostream_iterator:

std::vector<int> data;
 . . .  // Acquire data.
std::copy(data.begin(  ), data.end(  ), 
          std::ostream_iterator(std::cout, "\n"));

The following are the member functions of ostream_iterator: