将多个集合元素合并到一个集合中

2022-01-17 00:00:00 set c++ stl

我想知道是否有任何 std 库或 boost 工具可以轻松地将多个集合的内容合并为一个.

I would like to know if there is any std library or boost tool to easily merge the contents of multiple sets into a single one.

就我而言,我有一些想要合并的整数集.

In my case I have some sets of ints which I would like to merge.

推荐答案

你可以这样做:

std::set<int> s1;
std::set<int> s2;
// fill your sets
s1.insert(s2.begin(), s2.end());

相关文章