Reputation: 155
I'm trying to make the intersection of two sets using the following code and if the result is different than the empty set i want to insert the first of my sets into a set of sets.
std::set<int> set1,set2;
std::set<set<int> > result;
std::set<int> intersection;
set_intersection(set1.begin(),set1.end(),set2.begin(),set2.end(),std::back_inserter(intersection));
if(!intersection.empty()) result.insert(set1);
However i get the following error: 'class std::set' has no member named 'push_back'. What is the problem? Thanks in advance.
Upvotes: 1
Views: 915
Reputation: 206567
std::back_inserter
uses std::back_inserter_iterator
, which calls push_back()
on the container.
Use std::inserter
when the output is an std::set
.
std::set<int> set1,set2;
std::set<int> intersection;
std::set_intersection(set1.begin(),set1.end(),set2.begin(),set2.end(),
std::inserter(intersection, intersection.begin()));
Upvotes: 2