this is my program,i just define the in ,haven't use it,but,after compiled,i execute the result, the program ask me input something. i have no idea...who can help me , tell me why?
best wishes!
1 2 3 4 5 6 7
#include<iostream>
#include<iterator>
usingnamespace std;
int main()
{
istream_iterator<int> in(cin);
}
> just define the in ,haven't use it,but,after compiled,
> i execute the result, the program ask me input something.
The actual read operation is performed when the iterator is incremented, not when it is dereferenced. The first object may be read when the iterator is constructed or when the first dereferencing is done. http://en.cppreference.com/w/cpp/iterator/istream_iterator
What if it was constructed on a stream that was already at the end but the eof flag had not been set? Could the iterator compare equal to the end iterator? If so, would that mean the equality comparison would attempt to fetch from the stream, meaning the operator cannot operate on const objects?
> What if it was constructed on a stream that was already at the end but the eof flag had not been set?
> Could the iterator compare equal to the end iterator?
My understanding is that in an implementation where the constructor does not read the first object, it would do a peek().