3.删除
//删除
/*
int main()
{
set<int> s;
s.insert({ 2,4,5,2,6,8,10,15 });
for (auto e : s)
{
cout << e << " ";
}
cout << endl;
//删除最小的元素就删除排序后的首元素
s.erase(s.begin());
for (auto e : s)
{
cout << e << " ";
}
cout << endl;
//指定删除元素并判断是否删除成功
//可以使用erase的返回值统计待删除元素出现的次数来判断是否删除成功
int x = 0;
cout << "输入你要删除的元素:";
cin >> x;
int num = s.erase(x);
if (num)
{
cout << "删除成功" << endl;
for (auto e : s)
{
cout << e << " ";
}
cout << endl;
}
else
{
cout << "删除失败" << endl;
for (auto e : s)
{
cout << e << " ";
}
cout << endl;
}
//使用迭代器删除
//如果未查找到则直接返回迭代器尾部
auto pos = s.find(x);
if (pos != s.end())
{
s.erase(x);
cout << "删除成功" << endl;
for (auto e : s)
{
cout <