gpt4 book ai didi

c++ - 使用 vector 的 Unordered_map

转载 作者:行者123 更新时间:2023-11-28 07:43:05 31 4
gpt4 key购买 nike

我有一个 unordered_map:

std::tr1::unordered_map<unsigned int, vector<unsigned int> > duplicates;

我想插入:

duplicates.insert(make_pair(1, 2));
duplicates.insert(make_pair(1, 5));
duplicates.insert(make_pair(1, 6));

进入 vector ,因为它们共享相同的 key 。我使用 for 循环来插入对。如果没有项目共享相同的键,我该如何初始化 vector ,这是我第一次在不搜索整个 unordered_map 的情况下找到该键?

我不想先使用查找(如果存在则获取 vector )然后插入。这可能吗?

最佳答案

很抱歉,如果我误解了你的问题,但也许你会发现类似 unordered_multimap 的用途?

Unordered multimaps are associative containers that store elements formed by the combination of a key value and a mapped value, much like unordered_map containers, but allowing different elements to have equivalent keys.

关于c++ - 使用 vector 的 Unordered_map,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15444294/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com