Qn on STL multimaps

If I change the key of a multimap to another value,
for e.g. iter->first = 80;
Will the map be reordered such that the element I just changed would be placed in the correct position?
If yes, then where does iter point to after the operation?

If I like to change the value of the key, would it be better to erase it and then insert the element again?
Last edited on
After changes to any STL container, most iterators are invalidated and you'd always be better off getting a new one than testing the old one.
Anyway I believe associative containers are always put in key order.
You cannot change the key. You can only change the value bound to it, as I recall.
Last edited on
Yes, you must remove the element first and reinsert with the new key.
Would removing and reinserting the new key cause memory fragmentation?
Depends on what the type of the value is. Usually fragmentation isn't an issue though.
Topic archived. No new replies allowed.