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

时间:2017-03-01 17:16:38

标签: c++ stl iterator set stdset

我试过这样做:

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

// fill the set with something

mySet.find( make_pair(someValueX, someValueY) )->first = newX;

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

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)) ===||

1 个答案:

答案 0 :(得分:6)

std::set的成员是const,因为更改这些成员可能会使他们的订单无效。您必须擦除该对并在更改后重新插入它。