
AMDG Max wrote:
const _Ty& operator*() const { // return designated value return (_Myval); }
_Myt& operator++() { // preincrement _Getval(); return (*this); }
IMO, it should be modified as:
const _Ty& operator*() //const { // return designated value _Getval(); return (_Myval); }
_Myt& operator++() { // preincrement return (*this); }
The main problem of the current design of istream_iterator is that it always swallow one extra object, of the template parameter type, prepared for the coming * or -> operator. This makes the coming plain >> operator a distance forward of where it shoud be.
I've tested with this modification and found it works well. Please note that I've simply commented out the trailing const qualifier for the * and -> operator, to make things simpler and more straightforward. Obviously, furthur modification is to be made to make the code to a product level.
I want to know whether this change makes sense?
Well, it solves your problem, but it creates other problems instead. For example, what should this do: std::istream_iterator<int> iter(std::cin); std::advance(iter, 10); Or this: std::istream_iterator<int> iter(std::cin); if(*iter != 10) { std::cout << *iter; } In Christ, Steven Watanabe