Original Post
im a bit confused with the following code form Josuttis STL book. from what i understand it works as so... 1. Create an istream iterator, read info from console, and set intreader to beginning of input buffer. 2. create an end of file iterator, (default istream/ostream iterator) 3. While we havent reached the end of the text just read in, output the text, and iterating over each int. 4. When reached end of text end app. Yet the loop goes over again, and reads input again, but i cant seem to see where data is being read again, the while loop just checks for end of file.
#include <iostream>
#include <iterator>
using namespace std;
int main()
{
// create istream iterator that reads integers from cin
istream_iterator<int> intReader(cin);
// create end-of-stream iterator
istream_iterator<int> intReaderEOF;
/* while able to read tokens with istream iterator
* - write them twice
*/
while (intReader != intReaderEOF) {
cout << "once: " << *intReader << endl;
cout << "once again: " << *intReader << endl;
++intReader;
}
}