如何更新一组std :: pair中的成员?

Tud*_*oiu 2 c++ iterator stl set stdset

我试过这样做:

std::set< pair<int, int> > mySet;

// fill the set with something

mySet.find( make_pair(someValueX, someValueY) )->first = newX;
Run Code Online (Sandbox Code Playgroud)

但是我在编译时遇到以下错误:

error: assignment of member 'std::pair<int, int>::first' in read-only object|
||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===||
Run Code Online (Sandbox Code Playgroud)

ala*_*ain 6

成员std::setconst,因为改变他们可能使他们的订单无效.您必须擦除该对并在更改后重新插入它.