
删除list第10个元素
By: a guest on
May 14th, 2012 | syntax:
C++ | size: 0.69 KB | hits: 22 | expires: Never
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <strstream>
#include <string>
using namespace std;
int main()
{
strstream s;
list<string> coll;
for (int i = 0; i < 20; ++i)
{
s << i + 1;
string str;
s >> str;
s.clear();
coll.push_back(str);
}
int i = 1;
for (auto pos = coll.begin(); pos != coll.end();)
{
cout << *pos << " ";
if (i == 10)
coll.erase(pos++);
else
++pos;
++i;
}
cout << endl;
copy (coll.begin(), coll.end(),
ostream_iterator<string>(cout, " "));
system("pause");
}