Why use iterators instead of array indices?

前端 未结 27 2178
萌比男神i
萌比男神i 2020-11-22 15:45

Take the following two lines of code:

for (int i = 0; i < some_vector.size(); i++)
{
    //do stuff
}

And this:

for (som         


        
27条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-22 16:17

    I probably should point out you can also call

    std::for_each(some_vector.begin(), some_vector.end(), &do_stuff);

提交回复
热议问题