cppannotations/yo/stl/istreamiterators.yo
2010-11-06 15:47:24 +00:00

24 lines
1 KiB
Text

The hi(istream_iterator)tt(istream_iterator<Type>) can be used to define a set
of iterators for
hi(istream: iterator) tt(istream) objects. The general form of the
tt(istream_iterator) iterator is:
verb(
istream_iterator<Type> identifier(istream &in)
)
Here, tt(Type) is the type of the data elements read from the tt(istream)
stream. It is used as the `begin' iterator in an interator range. tt(Type) may
be any type for which oprshift() is defined in combination with tt(istream)
objects.
The default constructor is used as the end-iterator and corresponds to the
i(end-of-stream). For example,
verb(
istream_iterator<string> endOfStream;
)
The em(stream) object that was specified when defining the
begin-iterator is em(not) mentioned with the default constructor.
Using tt(back_inserter) and tt(istream_iterator) adaptors, all strings
from a stream can easily be stored in a container. Example (using i(anonymous)
tt(istream_iterator) adaptors):
verbinclude(examples/istreamiterator.cc)