Standard C++ Library Class Reference
//Create an insert_iterator for odd
insert_iterator<set<int, less<int> > >
odd_ins(odd, odd.begin());
//Demonstrate set_difference
cout << "The result of:" << endl << "{";
copy(all.begin(),all.end(),
ostream_iterator<int>(cout," "));
cout << "} - {";
copy(even.begin(),even.end(),
ostream_iterator<int>(cout," "));
cout << "} =" << endl << "{";
set_difference(all.begin(), all.end(),
even.begin(), even.end(), odd_ins);
copy(odd.begin(),odd.end(),
ostream_iterator<int>(cout," "));
cout << "}" << endl << endl;
return 0;
}
Output :
The result of:
{1 2 3 4 5 6 7 8 9 10 } - {2 4 6 8 10 12 } =
{1 3 5 7 9 }
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_symmetric_difference