0

Hi,

If I have a std::vector of objects and I need to iterate through all its elements, is it faster to do:

for (vector::iterator i = myvec.begin(); i != myvec.end(); ++i)
    //blah

or

for (int i = 0; i < myvec.size(); ++i)
   // myvec[i] blah

Or are they equally fast?

Thanks
Xorlium

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by firstPerson
0

The second one would probably use less memory. And normally you would use the second one unless you have a compelling reason to use the first.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.