Name

istream_iterator class template — Input iterator to read items from an istream

Synopsis

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 ...

Get C++ In a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.