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);
这是一个特殊的“前哨”值,其唯一目的是与另一个达到EOF的istream_iterator()
比较时返回值true
。
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
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.