Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
Standard C++ Library Module Reference Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

istream_iterator

Module:  Standard C++ Library   Library:  Iterators


istream_iterator iterator

Local Index

Members

Non-Members

Summary

A stream iterator that has iterator capabilities for istreams. This iterator allows generic algorithms to be used directly on streams.

Synopsis

#include <iterator>

namespace std {
  template <class T, class charT, 
            class traits = char_traits<charT>, 
            class Distance = ptrdiff_t>
  class istream_iterator : 
          public iterator<input_iterator_tag, T, 
                          Distance, const T*, const T&>;
}

Description

Stream iterators are the standard iterator interface for input and output streams.

The class template istream_iterator reads elements from an input stream using operator >>(). A value of type T is retrieved and stored when the iterator is constructed and each time operator++() is called. The iterator is equal to the end-of-stream iterator value if the end-of-file is reached. You can use the constructor with no arguments to create an end-of-stream iterator. The only valid use of this iterator is to compare to other iterators when checking for end of file. Do not attempt to dereference the end-of-stream iterator; it plays the same role as the past-the-end iterator of the end() function of containers. Since an istream_iterator is an input iterator, you cannot assign to the value returned by dereferencing the iterator. This also means that istream_iterators can only be used for single pass algorithms.

Since a new value is read every time the operator++() is used on an istream_iterator, that operation is not equality-preserving. This means that i == j does not mean that ++i == ++j (although two end-of-stream iterators are always equal).

Interface

Member Types

char_type; 
traits_type; 
istream_type; 

Constructors

istream_iterator();
istream_iterator(istream_type& s);
istream_iterator(const istream_iterator& x);

Operators

const T& 
operator*() const;
const T*
operator->() const;
istream_iterator& operator++()
istream_iterator operator++(int)

Nonmember Operators

template <class T, class charT, class traits, class Distance> 
bool 
operator==(const istream_iterator<T,charT,traits,
            Distance>& x,
            const
            istream_iterator<T,charT,traits,Distance>& y)
template <class T, class charT, class traits, class Distance> 
bool 
operator!=(const istream_iterator<T,charT,traits,Distance>& x,
           const istream_iterator<T,charT,traits,Distance>& y)

Example

See Also

Iterators, ostream_iterator

Standards Conformance

ISO/IEC 14882:1998 -- International Standard for Information Systems -- Programming Language C++, Section 24.5.1



Previous fileTop of DocumentContentsIndex pageNext file

Copyright (c) 1994-2006 Rogue Wave Software, a Quovadx Division.
Licensed under the Apache License, Version 2.0.
Contact Rogue Wave about documentation or support issues. You can also seek help from other developers through the Apache stdcxx community (see below).

For more information on the Rogue Wave Standard C++ Library under open source, see Section 1.2 of the user's guide.