gpt4 book ai didi

c++ - 在 C++ 中,我可以将一个集合插入一个集合作为值的映射中吗?

转载 作者:行者123 更新时间:2023-11-28 01:28:25 27 4
gpt4 key购买 nike

map<int, set<int>> m;
set<int> n;
m[1].insert(3);
n.insert(3);
n.insert(4);
m[1].insert(n); //can I do this?

最后一行是否正确?如果没有,有什么简单的方法可以实现吗?

最佳答案

Is the last line correct?

没有。你想要的应该是inserting来自另一个 std::set 的元素,你可以

m[1].insert(n.begin(), n.end()); // insert all the elements of n into m[1]

关于c++ - 在 C++ 中,我可以将一个集合插入一个集合作为值的映射中吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52771343/

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