在使用set模板类前,请添加头文件 #include <set>
要使用上述算法,请添加头文件 #include <algorithm>
int first[] = { 5,10,15,20,25 }; int second[] = { 50,40,30,20,10 }; set<int> a(first, first + 5); set<int> b(second, second + 5); std::vector<int> v(10);// 0 0 0 0 0 0 0 0 0 0 std::vector<int>::iterator it; it = set_intersection(a.begin(), a.end(), b.begin(), b.end(), v.begin()); //10 20 0 0 0 0 0 0 0 0 //it 指向第三个元素 v.resize(it - v.begin());// 10 20
原文:https://www.cnblogs.com/woxiaosade/p/10793497.html