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

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

最佳答案

std::set 的成员是const,因为更改它们可能会使它们的排序无效。您必须删除该对并在更改后重新插入。

关于c++ - 如何更新一组 std::pair 中的成员?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42538013/

相关文章:

c++ - C++中的预处理器指令与指令有什么区别

c++ - 可修改的左值?

c++ - std::find_if_not() 返回什么类型?

c++ - std::map 多个迭代器、删除及其值

c++ - 我无法理解 std::istream_iterator 的使用

c++ - 如何获取 GDB 的行号?

C++ 文件 I/O - 程序挂起

c++ - 有没有办法防止在 STL unordered_map 上插入或删除?

java - 如何通过Android提取表数据

java - 数据库连接关闭后无法关闭迭代器