user273324
user273324

Reputation: 162

Index of vector iterator

So I have a basic vector iterator, which looks like:

for (std::vector<string>::iterator i = vec.begin(); i != vec.end(); ++i)
{
    // Need the index here
}

I've tried using &i but that just returns true. I need to return the index. Would I need to create my own integer?

Upvotes: 4

Views: 6033

Answers (1)

Wojtek Surowka
Wojtek Surowka

Reputation: 21003

If by 'ID' you mean index, use

i - vec.begin()

Upvotes: 7

Related Questions