-
Question on Maps
consider an example where i have a map holding keys :1000,2000,10000,30000
mapped values are 1,2,3,4
ie:
1--- 10000
3-----10000
2----20000
4----30000
all i do to delete an elemnt is withy key 10000:
Code:
it= mymap.find(10000);
mymap.erase(it);
But wat if i want the 3-10000 pair to be deleted..
but not 1-10000
can ialso specify the mapped value to delete the pair ...
If yes what snippet should i add to the above
-
Firstly, are you using a std::multi_map, because std::map can only contain one item with key 10000.
Code:
std::map<int, int> map;
map[10000] = 1;
map[10000] = 3; //overwrites the mapped value (1) with 3
Then you'll probably need to find the range with key value 10000 (equal_range) and loop over those, erasing the items that have a desired mapped_value (3), leaving the others (1).
-
s i use Multimaps...fine thanks for the reply