c++ STL set difference

后端 未结 10 1708
梦如初夏
梦如初夏 2020-12-23 11:05

Does the C++ STL set data structure have a set difference operator?

10条回答
  •  遥遥无期
    2020-12-23 11:33

    Yes there is, it is in and is called: std::set_difference. The usage is:

    #include 
    #include 
    #include 
    // ...
    std::set s1, s2;
    // Fill in s1 and s2 with values
    std::set result;
    std::set_difference(s1.begin(), s1.end(), s2.begin(), s2.end(),
        std::inserter(result, result.end()));
    

    In the end, the set result will contain the s1-s2.

提交回复
热议问题