Domanda

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?

È stato utile?

Soluzione

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!)

Altri suggerimenti

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"));
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top