c ++ STL集合差异 [英] c++ STL set difference
本文介绍了c ++ STL集合差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
C ++ STL集数据结构是否有一个集合差分运算符?
Does the C++ STL set data structure have a set difference operator?
推荐答案
c $ c>< 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
。
这篇关于c ++ STL集合差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文