【发布时间】:2017-11-11 14:17:47
【问题描述】:
面临删除集合中最后一个元素的问题:
#include <bits/stdc++.h>
using namespace std;
int main()
{
set < pair <int,int > > a;
a.insert(make_pair(2,3));
auto it = a.rbegin();
a.erase(it.base()); // for deleting last element in set
cout << a.size() << endl;
return 0;
}
遇到 runtime 问题,也尝试过 auto、Iterator 和 Const iterator,但无法正常工作.有没有其他方法可以从集合中删除一个元素?
编辑:如何根据迭代器引用删除特定元素? 如果我喜欢:
auto it=a.begin();
a.erase(it); Here it = reference to the element for deletion
它不起作用。基于迭代器引用的任何其他删除方式?
【问题讨论】: