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++;
}