I try to do a set intersection of two STL set containers and output into an STL set contrainer. I have tried to look around, but STL set data type does not have this kind of function. STL algorithm has set_intersection() (http://www.cplusplus.com/reference/algorithm/set_intersection/). But I cannot use an STL set container as the output for this set_intersection().
Can anyone help me for this problem?
Do I need to use an STL vector container as an temporary output and copy from it to an STL set container?
Tried to use a set<int>::iterator for what? The last parameter to set_intersection? Of course you can't.
Because set provides an ordering of elements, you can't use iterators to add elements to the set, as you
could then attempt an insert that would break the ordering constraint. For that reason, set<>::iterator
is a typedef of set<>::const_iterator. That's why I used std::inserter. It does the right thing.