C++: Proper way to iterate over STL containers

后端 未结 8 1474
灰色年华
灰色年华 2021-01-06 04:55

In my game engine project, I make extensive use of the STL, mostly of the std::string and std::vector classes.

In many cases, I have to ite

8条回答
  •  滥情空心
    2021-01-06 05:50

    STL containers support Iterators

    vector v;
    for (vector::iterator it = v.begin(); it!=v.end(); ++it) {
        cout << *it << endl;
    }
    

    size() would be re-computed every iteration.

提交回复
热议问题