I have been trying to find the intersection between two std::set in C++, but I keep getting an error.
I created a small sample test for this
#include
You havent provided an output iterator for set_intersection
template
OutputIterator set_intersection ( InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2,
OutputIterator result );
Fix this by doing something like
...;
set intersect;
set_intersection(s1.begin(),s1.end(),s2.begin(),s2.end(),
std::inserter(intersect,intersect.begin()));
You need a std::insert iterator since the set is as of now empty. We cannot use back_ or front_inserter since set doesnt support those operations.