我有以下示例:
// remove from list
#include <iostream>
#include <list>
using namespace std;
int main ()
{
int myints[]= {17,89,89,7,14};
list<int> mylist (myints,myints+5);
mylist.remove(89);
cout << "mylist contains:";
for (list<int>::iterator it=mylist.begin(); it!=mylist.end(); ++it)
cout << " " << *it;
cout << endl;
return 0;
}
结果是:
17, 7, 14
问题在于它删除了 89 的两个实例。有没有简单的方法来删除 89 的一个实例?