cppannotations/yo/stl/ostreamiterators.yo
2010-02-28 16:34:35 +00:00

21 lines
1.2 KiB
Text

An hi(ostream_iterator)tt(ostream_iterator<Type>) adaptor
can be used to pass an hi(ostream: iterator)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
combinations 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 is use of tt(in.unsetf(ios::skipws)). It is used to clear the
hi(skipws)tt(ios::skipws) flag. As a consequence white space characters are
simply returned by the operator, and the file is copied character by
character. Here is the program:
verbinclude(stl/examples/ostreamiterator.cc)