STL set intersection question

P

Phil

Hello,

I'm trying to get the result of a set intersection and I'm sure that I've
made a very basic error.

A Google search has helped but I'm still not quite there. Can someone show
me the error?

set<int> firstSet;

secondSet.insert(1);
secondSet.insert(2);

set<int> secondSet;

secondSet.insert(2);

set<int> resultSet;

resultSet = set_intersection(firstSet.begin(), firstSet.end(),
secondSet.begin(), secondSet.end(), resultSet.begin());
 
J

joosteto

Phil said:
Hello,

I'm trying to get the result of a set intersection and I'm sure that I've
made a very basic error.

A Google search has helped but I'm still not quite there. Can someone show
me the error?

set<int> firstSet;

secondSet.insert(1);
secondSet.insert(2);

set<int> secondSet;

secondSet.insert(2);

set<int> resultSet;

resultSet = set_intersection(firstSet.begin(), firstSet.end(),
secondSet.begin(), secondSet.end(), resultSet.begin());

This does seem to compile:
vector<int> vi;
set_intersection(firstSet.begin(), firstSet.end(),
secondSet.begin(), secondSet.end(),
vi.begin());
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top