Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change a set element?

I want to change the element in a set, so I used set<T>::iterator. However, the compiler argues "the element is const". Then I realized that set<T>::iterator is a const_iterator...

So, how I can change the element? Erase it and then insert a new one?

like image 387
Eric.Q Avatar asked Mar 07 '12 11:03

Eric.Q


1 Answers

The elements of the set will be in sorted order. If you are allowed to modify an element, then this sorting order can not be maintained. Hence you can not modify the item. You need to erase the existing element and insert a new one.

like image 190
Naveen Avatar answered Sep 21 '22 15:09

Naveen