首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

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

2012-03-06 
100分,求解一个STL的问题!#includeiostream#includevector#includealgorithmusingnamespacestdstru

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

热点排行