注册 登录
编程论坛 C++教室

谁能帮我看看错在哪呢 MAP容器问题

tantan821 发布于 2010-08-14 17:36, 418 次点击
#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;
}
0 回复
1