I have a vector of objects and am iterating through it using a range-for loop. I am using it to print a function from the object, like this:
vector<thisObject> storedValues;
//put stuff in storedValues
for(auto i:storedValues)
{
cout<<i.function();
}
But I want to print the index too. My desired output is:
1: value
2: value
//etc
I was going to just use a counter that I increased each time, but that seemed very inefficient. Is there a better way?
See Question&Answers more detail:os