Use of iterators over array indices

前端 未结 9 1446
执念已碎
执念已碎 2020-12-18 22:54

I just wanted to know what is the main advantage of using the iterators over the array indices. I have googled but i am not getting the right answer.

9条回答
  •  独厮守ぢ
    2020-12-18 23:33

    The STL contains algorithms, such as transform and for_each that operate on containers. They don't accept indices, but use iterators.

    Iterators help hide the container implementation and allow the programmer to focus more on the algorithm. The for_each function can be applied to anything that supports a forward iterator.

提交回复
热议问题