istream_iterator class template — Input iterator to read items from an istream
template <typename T, typename charT = char, typename traits = char_traits<charT>, typename Distance = ptrdiff_t> class istream_iterator : public iterator<input_iterator_tag, T, Distance, const T*, const T&> { public: typedef charT char_type; typedef traits traits_type; typedef basic_istream<charT,traits> istream_type; istream_iterator( ); istream_iterator(istream_type& stream); istream_iterator(const istream_iterator<T,charT,traits,Distance>& x); ~istream_iterator( ); const T& operator*( ) const; const T* operator->( ) const; istream_iterator<T,charT,traits,Distance>& operator++( ); istream_iterator<T,charT,traits,Distance> operator++(int); };
The istream_iterator
class
template wraps an input iterator around an input stream (an instance
of basic_istream
), making the
stream appear to be a sequence of items, each of type T
.
Example 13-20
(under the front_inserter
function template) shows how an istream_iterator
can be used to read a
series of integers from a file.
The following are the member functions of istream_iterator
:
istream_iterator
( )
Constructs an istream_iterator
that denotes the
end of the stream. End-of-stream iterators are equal to each
other and are not equal to any other istream_iterator
.
istream_iterator
(istream_type& stream)
Constructs an istream_iterator
to read from a
stream. The constructor might read the first item from the
stream. An istream_iterator
that wraps a stream is equal to an end-of-stream iterator when
stream.eof( )
is true
.
istream_iterator
(const
istream_iterator<T,charT,traits,Distance>&
iter)
Constructs a copy of iter
. Note that two istream_iterator
objects are the
same (operator==
is true)
if they point to the same stream object.
const T&
operator*
( )
const
Returns the item that was read most recently from the stream.
operator->
Returns a pointer to the item that was read most recently from the stream.
istream_iterator<T,charT,traits,Distance>&
operator++
( )
Reads the next item from the stream using operator>>
. The return value
is a copy of *this
, made
prior to reading from the stream.
istreambuf_iterator class
template, ostream_iterator
class template, basic_istream
in <istream>