how to compare two std::set?

前端 未结 4 1982
一向
一向 2021-02-03 18:45

I do such comparison of two std::set

#include 
#include 
using namespace std;

#include 
#include 

        
4条回答
  •  野性不改
    2021-02-03 19:10

    There are several set operations in C++ standard library header .

    std::set_difference gives those elements that are in set 1 but not set 2.

    std::set_intersection gives those elements that are in both sets.

    std::set_symmetric_difference gives those elements that appear in one of the sets but not both.

    std::set_union gives those elements that are in either set 1 or set 2.

    The algorithms above can also be applied to STL containers other than std::set, but the containers have to be sorted first (std::set is sorted by default).

提交回复
热议问题