#include <iostream>
#include <ctime>
#include <map>
using namespace std;
typedef struct itemstruct
{
int a;
char b[20];
}itemS;
itemS s[4] = {{102,"what"},
{33, "hello"},
{198,"world"},
{45, "c++"}
};


int main()
{
map<string, itemS> mymap;
string str[4] = {"1st","2nd","3rd","4th"};
for(int i = 0; i<4; i++)
{
mymap.insert(make_pair(str[i], s[i]));
}


map<string,itemS>::iterator it;
for(it=mymap.begin(); it!=mymap.end(); it++)
{
if(it->second.a >100){
i=mymap.erase(it); ----->正确
mymap.erase(it); ----->it失效..
}
}
//first是Key, second是value;
for(it = mymap.begin(); it!=mymap.end(); it++)
{
cout<<it->first<<" "<<it->second.a<<" "<<it->second.b<<endl;
}
system("pause");
return 0;
}

相关文章:

  • 2021-12-11
  • 2022-12-23
  • 2022-12-23
  • 2022-02-13
  • 2021-10-06
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-01-24
  • 2022-12-23
  • 2022-12-23
  • 2021-12-21
  • 2022-12-23
相关资源
相似解决方案