谁能帮我看看错在哪呢 MAP容器问题
#include <iostream>#include <map>
#include <vector>
#include <string>
using namespace std;
int main()
{
map< string,vector<string> > children;
string surname,childname;
do{
cout<<"Enter surname(Ctrl+z):"<<endl;
cin>>surname;
if (!cin)
break;
vector<string> chd;
pair< map<string,vector<string> >::iterator,bool> ret=children.insert
(make_pair(surname,chd));
if (!ret.second){
cout<<"repeted surname:"<<surname<<endl;
continue;
}
cout<<"Enter children's name(ctrl+z):"<<endl;
while (cin>>childname)
ret.first->second.push_bake(childname);
cin.clear();
}while(cin);
cin.clear();
cout<<"Enter a surname to search:"<<endl;
cin>>surname;
map< string,vector<string> >::iterator iter=children.find(surname);
if (iter==children.end())
cout<<"no this surname"<<surname<<endl;
else{
cout<<"children:"<<endl;
vector<string>::iterator it=iter->second.begin();
while (it!=iter->second.end())
cout<<*it++<<endl;
}
return 0;
}