Vijay
Vijay

Reputation: 67211

How to create a std::set from the symmetric difference of two sets

I Have two sets of strings.

set<string> A;
set<string> B;

I will insert some elements into both the sets and some of the elements that I insert into them are common elements.

I can basically get the elements

using

std::set_difference

I can also get the common elements in both the sets by

using

std::set_intersection

How can I get the elements which and present only in A and only in B and put them in a different set?

Total idea is creating a set which will not have the common elements but all the elements in both the sets.

In mathematical language:

(A(UNION)B)-(A(intersection)B)

Upvotes: 1

Views: 126

Answers (2)

Some programmer dude
Some programmer dude

Reputation: 409166

How about std::set_symmetric_difference? It seems to fit what you want.

Upvotes: 2

Naveen
Naveen

Reputation: 73443

You can use set_symmetric_difference

Upvotes: 1

Related Questions