Standard C++ Library Class Reference

//Initialize some sets
int a1[] = {1,3,5,7,9,11};
int a3[] = {3,5,7,8};
set<int, less<int> > odd(a1,a1+6), result,
small(a3,a3+4);
//Create an insert_iterator for result
insert_iterator<set<int, less<int> > >
res_ins(result, result.begin());
//Demonstrate set_symmetric_difference
cout << "The symmetric difference of:" << endl << "{";
copy(small.begin(),small.end(),
ostream_iterator<int>(cout," "));
cout << "} with {";
copy(odd.begin(),odd.end(),
ostream_iterator<int>(cout," "));
cout << "} =" << endl << "{";
set_symmetric_difference(small.begin(), small.end(),
odd.begin(), odd.end(), res_ins);
copy(result.begin(),result.end(),
ostream_iterator<int>(cout," "));
cout << "}" << endl << endl;
return 0;
}
Output :
The symmetric difference of:
{3 5 7 8 } with {1 3 5 7 9 11 } =
{1 8 9 11 }
Warning
If your compiler does not support default template parameters, then you need to always supply
the Compare template argument and the Allocator template argument. For instance, you will
need to write :
set<int, less<int>, allocator>
instead of :
set<int>
See Also
includes, set, set_union, set_intersection, set_difference