标题:谁能帮我看看错在哪呢 MAP容器问题
只看楼主
tantan821
Rank: 2
等 级:论坛游民
帖 子:21
专家分:19
注 册:2010-5-15
 问题点数:0 回复次数:0 
谁能帮我看看错在哪呢 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;
}
搜索更多相关主题的帖子: MAP 容器 
2010-08-14 17:36



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-315700-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.614562 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved