Quantcast
Channel: User Karthik T - Stack Overflow
Viewing all articles
Browse latest Browse all 42

Answer by Karthik T for How to find the intersection of two STL sets?

$
0
0

You haven't provided an output iterator for set_intersection

template <class InputIterator1, class InputIterator2, class OutputIterator>OutputIterator set_intersection ( InputIterator1 first1, InputIterator1 last1,                                  InputIterator2 first2, InputIterator2 last2,                                  OutputIterator result );

Fix this by doing something like

...;set<int> 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 std::back_inserter or std::front_inserter since set doesn't support those operations.


Viewing all articles
Browse latest Browse all 42

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>