stlab.adobe.com Adobe Systems Incorporated

istream_iterator

iterators.gif
type.gif
Category: iterators Component type: type

Description

An istream_iterator is an InputIterator that performs formatted input of objects of type T from a particular istream. When end of stream is reached, the istream_iterator takes on a special end of stream value, which is a past-the-end iterator. Note that all of the restrictions of an InputIterator must be obeyed, including the restrictions on the ordering of operator* and operator++ operations.

Example

Fill a Vector with values read from standard input.

Vector<int> V;
copy(istream_iterator<int>(cin), istream_iterator<int>(),
     back_insert_iterator(V));   

Definition

Defined in the standard header iterator, and in the nonstandard backward-compatibility header iterator.h.

Template parameters

Parameter Description Default
T The istream_iterator's value type. Operator* returns a const T&.  
Distance The istream_iterator's distance type. ptrdiff_t

Model of

InputIterator

Type requirements

The value type T must be a type such that cin >> T is a valid expression.

The value type T must be a model of DefaultConstructible.

The distance type must, as described in the InputIterator requirements, be a signed integral type.

Public base classes

None.

Members

Member Where defined Description
istream_iterator() istream_iterator See below.
istream_iterator(istream&) istream_iterator See below.
istream_iterator(const istream_iterator&) trivial The copy constructor
istream_iterator& operator=(const istream_iterator&) trivial The assignment operator
const T& operator*() const InputIterator Returns the next object in the stream.
istream_iterator& operator++() InputIterator Preincrement.
istream_iterator& operator++(int) InputIterator Postincrement.
bool operator==(const istream_iterator&, const istream_iterator&) trivial The equality operator. This is a global function, not a member function.
input_iterator_tag iterator_category(const istream_iterator&) iterator_tags Returns the iterator's category.
T* value_type(const istream_iterator&) iterator_tags Returns the iterator's value type.
Distance* distance_type(const istream_iterator&) iterator_tags Returns the iterator's distance type. <

New members

These members are not defined in the InputIterator requirements, but are specific to istream_iterator.

Function Description
istream_iterator() The default constructor: Constructs an end-of-stream iterator. This is a past-the-end iterator, and it is useful when constructing a "range".
istream_iterator(istream& s) Creates an istream_iterator that reads values from the input stream s. When s reaches end of stream, this iterator will compare equal to an end-of-stream iterator created using the default constructor.

Notes

See also

ostream_iterator, InputIterator, OutputIterator.

Copyright © 2006-2007 Adobe Systems Incorporated.

Use of this website signifies your agreement to the Terms of Use and Online Privacy Policy.

Search powered by Google