读书人

100分求解一个STL的有关问题

发布时间: 2012-03-06 20:47:55 作者: rapoo

100分,求解一个STL的问题!
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

struct MRC
{
int boneCnt;
};
vector <MRC> temp;
void main()
{
MRC fff,fffa,faff;
fff.boneCnt = 10;
temp.push_back(fff);

fffa.boneCnt = 110;
temp.push_back(fffa);

faff.boneCnt = 1111;
temp.push_back(faff);

for(vector <MRC> ::iterator iS = temp.begin(); iS!=temp.end(); ++iS)
{
if(iS-> boneCnt ==110)
{
//temp.erase(remove(temp.begin(),temp.end(),??????????),temp.end());
??????????应该怎么写才能删除fffa啊?

}
}
system( "pause ");
}

??????????应该怎么写才能删除fffa啊?




[解决办法]
if(iS-> boneCnt ==110)
{
//temp.erase(remove(temp.begin(),temp.end(),??????????),temp.end());
??????????应该怎么写才能删除fffa啊?

}
=====
if (iS-> boneCnt == 110)
iS = temp.erase(iS);
[解决办法]


应该这个样写

vector <MRC> ::iterator iS = temp.begin();
while (iS != temp.end())
{
if(iS-> boneCnt ==10)
iS = temp.erase(iS);
else
iS++;
}

读书人网 >C++

热点推荐