Title
Which operations on istream_iterator trigger input operations?
Status
nad
Section
[istream.iterator]
Submitter
Andrew Koenig

Created on 2000-05-02.00:00:00 last changed 171 months ago

Messages

Date: 2010-10-21.18:28:33

Rationale:

The standard is clear as written: the stream is read every time operator++ is called, and it is also read either when the iterator is constructed or when operator* is called for the first time. In the example above, exactly two integers are read from cin.

There may be a problem with the interaction between istream_iterator and some STL algorithms, such as find. There are no guarantees about how many times find may invoke operator++.

Date: 2000-05-02.00:00:00

I do not think the standard specifies what operation(s) on istream iterators trigger input operations. So, for example:

        istream_iterator<int> i(cin);

        int n = *i++;

I do not think it is specified how many integers have been read from cin. The number must be at least 1, of course, but can it be 2? More?

History
Date User Action Args
2010-10-21 18:28:33adminsetmessages: + msg1989
2000-05-02 00:00:00admincreate