c++ STL设置差异

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

C++ STL 集合数据结构有集合差分算子吗?

Does the C++ STL set data structure have a set difference operator?

推荐答案

有,在<algorithm>中调用:std::set_difference.用法是:

Yes there is, it is in <algorithm> and is called: std::set_difference. The usage is:

#include <algorithm>
#include <set>
#include <iterator>
// ...
std::set<int> s1, s2;
// Fill in s1 and s2 with values
std::set<int> result;
std::set_difference(s1.begin(), s1.end(), s2.begin(), s2.end(),
    std::inserter(result, result.end()));

最后,集合 result 将包含 s1-s2.

In the end, the set result will contain the s1-s2.

相关文章