Search code examples
c++c++11iostreamistream-iterator

istream_iterator, black magic?


I don't understand why the second argument for_each is an empty iterator. Can someone explain this to me, please?

fstream("datfile.txt"); 
for_each(istream_iterator<string>(datfile), istream_iterator<string>(), rand_func);

Solution

  • It's a special "sentinel" value, whose only purpose is to return the value true when compared with another istream_iterator() that has reached EOF.