This is probably an easy question to answer, but I've been trying to change my syntax for using for loops with vectors to be more efficient. I was previously using the normal method for loops:
for (int i = 0; i < vector.size(); i++){
//code
}
But am trying to change my approach to the recommended use of iterators
for (const auto i : vector){
//code
}
I like this way as it looks cleaner and is obviously the way most people recommend, but the previous method allows me to use "i" so that I can have control of specific element numbers. So if I wanted to access the 5th element I could do that by putting "vector[i]" during the 5th iteration of the loop. I'm sure that the second approach allows for this as well and I'm just ignorant as to the specific code to use. Can someone recommend what they think is the best approach towards getting element access using the second method?