0
#include <map>
#include <set>
using namespace std;
map <string, set<pair<int, set<int>>>> dictonary;

int s()
{
    for (auto & i : dictonary["abc"])
    {
        i.second.insert(2);  //error C2663
    }
}

C2663:“std::_Tree>::insert”:5 个重载对“this”指针没有合法转换。

i.second被编译器认为是const合格的,因此禁止插入。

如果它不是错误,我该如何操作它?

4

1 回答 1

0

如果它不是错误,我该如何操作它?

您不能更改已经插入std::set到位的值,因为数据是有序的,并且修改会使不变量无效。您需要删除/修改/重新插入或使用不同的容器std::set

于 2017-12-26T20:26:11.223 回答