문제

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);
도움이 되었습니까?

해결책

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.

다른 팁

The default constructed istream_iterator is used as a sentinel that denotes the end of stream condition. When reading from the istream ends, the first iterator input to for_each will equal this sentinel iterator, thus terminating the for_each.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top