ostream_iterator


An iterator that outputs items (with an optional trailer) in a typesafe manner to an output stream.

Library

Standards<ToolKit>

Declaration


#include <iterator>

template< class T >
class ostream_iterator : public output_iterator

Interface

Constructor
ostream_iterator( ostream& stream )
Constructs an iterator associated with stream . Sets the iterator's trailer to an empty string.
Constructor
ostream_iterator( ostream& stream , char* trailer )
Constructs an iterator associated with stream . Sets the iterator's trailer to trailer .
=
ostream_iterator< T >& operator=( const T& value )
Writes value together with the iterator's trailer to the associated stream.
*
ostream_iterator< T >& operator *()
Returns a reference to the iterator.
++
ostream_iterator< T >& operator++()
Returns a reference to the iterator.
++
ostream_iterator< T > operator++( int )
Returns a copy of the iterator.
Example <ospace/osstd/examples/ostmit.cpp>
#include <iostream>
#include <iterator>
#include <algorithm>

int array[] = { 1, 5, 2, 4 };

void
main()
  {
  char* string = "hello";

  ostream_iterator< char > it1( cout );
  copy( string, string + 5, it1 );
  cout << "\n";

  ostream_iterator< int > it2( cout );
  copy( array, array + 4, it2 );
  cout << "\n";
  }

hello
1524

Copyright©1994-2026 Recursion Software LLC
All Rights Reserved - For use by licensed users only.