// test.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "iostream"
#include "algorithm"
#include "set"
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
set<int> set1;
set1.insert(1);
set1.insert(2);
set1.insert(3);
set<int> set2;
set2.insert(1);
set2.insert(2);
set2.insert(4);
set2.insert(5);
set<int> set3;
set<int>::iterator iter=set3.begin();
set_intersection(set1.begin(),set1.end(),set2.begin(),set2.end(),inserter(set3,iter));
copy(set3.begin(),set3.end(), ostream_iterator <int> (cout, " "));
cin.get();
return 0;
}
本文通过一个具体的C++程序示例介绍了如何使用C++标准库中的set容器进行交集运算,并展示了如何将结果输出到控制台。示例中使用了<algorithm>头文件中的set_intersection函数来实现两个整数集合的交集。
798

被折叠的 条评论
为什么被折叠?



