index of member of a map?
-
hi, how do i know index of an iterator of a map?
map::iterator it = mymap.find(3);
i want to know index of 'it' in mymap???
Zo.Naderi-Iran
You can increment a counter in a loop. But why do you need this.
std::map
always works on the key and so you must not use the index to perform any operations on the map. Here is something you could do -map num;
int j = 0;
for (auto i = num.begin(); i != num.end(); ++i, ++j)
{
if ((*i).first == 5)
cout << j << endl;
}Don't know if there is any other way to do this.
«_Superman_» _I love work. It gives me something to do between weekends.
-
hi, how do i know index of an iterator of a map?
map::iterator it = mymap.find(3);
i want to know index of 'it' in mymap???
Zo.Naderi-Iran
maps are not arranged in a simple linear order (they are trees), so there is no 'index' for an item.