Why use iterators instead of array indices?

前端 未结 27 2125
萌比男神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:10

    Even better than "telling the CPU what to do" (imperative) is "telling the libraries what you want" (functional).

    So instead of using loops you should learn the algorithms present in stl.

提交回复
热议问题