i have problem when i want to change element of set by using iterator.
This simple code may explain what i want to do.
set<int> s;
s.insert(12);
set<int>::iterator it = s.begin();
*it = 4; // error C3892: 'it' : you cannot assign to a variable that is const
Why i can not change value pointed to by normal iterator, not const_iterator?
In my code iterator was return by set::find(). Maybe is better way to pick specific element from set and change him.
A set is an ordered container (in particular they are implemented as balanced binary search trees). If you were able to change the value of the element through the iterator the order invariant would be broken. Depending on what you are trying to achieve you might be better off with a different container or obtaining the value, removing the element and inserting a new element into the set.