An ostream_iterator is an Output Iterator that performs formatted
output of objects of type T to a particular ostream.
Note that all of the
restrictions of an Output Iterator must be obeyed, including the
restrictions on the ordering of operator* and operator++
operations.
Example
Copy the elements of a vector to the standard output, one per line.
These members are not defined
in the Output Iterator requirements,
but are specific to ostream_iterator.
Function
Description
ostream_iterator(ostream& s)
Creates an ostream_iterator such that assignment of t through it
is equivalent to s << t.
ostream_iterator(ostream& s, const char* delim)
Creates an ostream_iterator such that assignment of t through it
is equivalent to s << t << delim.
Notes
[1]
Note how assignment through an ostream_iterator is implemented.
In general, unary operator* must be defined so that it returns a
proxy object, where the proxy object defines operator= to perform
the output operation. In this case, for the sake of simplicity, the
proxy object is the ostream_iterator itself. That is, *i simply
returns i, and *i = t is equivalent to i = t. You should not,
however, rely on this behavior. It is an implementation detail,
and it is not guaranteed to remain the same in future versions.