Reputation: 193
If I have two sets of data
set<string> A;
set<string> B;
use set_intersection I am able to obtain the data in the intersection part for the two sets.
How do I print out the data in the non-intersection part for the set A and set B, respectively?
Upvotes: 0
Views: 177
Reputation: 24163
set_symmetric_difference
puts the results into some iterable object.
So, you can copy values into an ostream
by wrapping it with an ostream_iterator
:
set<string> a;
set<string> b;
set_symmetric_difference(a.begin(), a.end(),
b.begin(), b.end(),
ostream_iterator<string>(cout, "\n"));
Upvotes: 1
Reputation: 272687
Use std::set_difference
or std::set_symmetric_difference
, depending on your needs.
(I'm too tired/lazy to write an example, but hopefully it should be obvious once you've read the above links!)
Upvotes: 4