1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
An hi(ostream_iterator)tt(ostream_iterator<Type>) adaptor can be used to pass
an tt(ostream) to algorithms expecting an OutputIterator. Two constructors are
available for defining tt(ostream_iterators):
verb( ostream_iterator<Type> identifier(ostream &outStream);
ostream_iterator<Type> identifier(ostream &outStream, char const *delim);)
tt(Type) is the type of the data elements that should be inserted into an
tt(ostream). It may be any type for which oplshift() is defined in
combination with tt(ostream) objects. The latter constructor can be used to
separate the individual tt(Type) data elements by ti(delimiter) strings. The
former constructor does not use any delimiters.
The example shows how link(tt(istream_iterators))(ISTREAMITERATORS) and an
tt(ostream_iterator) may be used to copy information of a file to another
file. A subtlety here is that you probably want to use
tt(in.unsetf(ios::skipws)). It is used to clear the
hi(skipws)tt(ios::skipws) flag. As a consequence whitespace characters are
simply returned by the operator, and the file is copied character by
character. Here is the program:
verbinclude(-a examples/ostreamiterator.cc)
|