Why does std::remove not work with std::set?

后端 未结 1 810
一生所求
一生所求 2020-12-10 05:44

The following code:

#include 
#include 
#include 

std::set s;

int main()
{
    s.insert(1);
    s.in         


        
相关标签:
1条回答
  • 2020-12-10 06:42

    std::set is ordered container, while std::remove changes order of elements in container placing elements that should be removed to the end, thus it can't be used with ordered containers where elements order is defined by predicate. You need to use:

    s.erase( 1);
    

    To remove 1 from set.

    0 讨论(0)
提交回复
热议问题