![[Dept of Engineering]](http://www.eng.cam.ac.uk/images/house_style/engban-s.gif)
includes()
set_union()
set_intersection()
set_difference()
set_symmetric_difference()
The following, while demonstrating some of these routines, uses 2 ideas that are often useful
copy(s1.begin(), s1.end(), ostream_iterator<int>(cout," "));
also puts spaces between the integers being printed. For now, don't worry if you don't understand the mechanics - it's useful so just use it!
insert() routine), front_inserter (which calls the container's
push_front() routine - which vectors for example don't have) or
back_inserter (which calls push_back()) do that for you.
[fontsize=\small,frame=single,formatcom=\color{progcolor}]
#include <algorithm>
#include <set>
#include <iostream>
#include <iterator> // needed for ostream_iterator
using namespace std;
int main()
{
//Initialize some sets
int a1[10] = {1,2,3,4,5,6,7,8,9,10};
int a2[6] = {2,4,6,8,10,12};
set<int> s1(a1, a1+10), s2(a2, a2+6), answer ;
cout << "s1=";
copy(s1.begin(), s1.end(),
ostream_iterator<int>(cout," "));
cout << "\ns2=";
copy(s2.begin(), s2.end(),
ostream_iterator<int>(cout," "));
//Demonstrate set_difference
set_difference(s1.begin(), s1.end(),
s2.begin(), s2.end(), inserter(answer,answer.begin()));
cout << "\nThe set-difference of s1 and s2 =";
copy(answer.begin(), answer.end(),
ostream_iterator<int>(cout," "));
cout << endl;
return 0;
}