| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 414 人关注过本帖
标题:谁能帮我看看错在哪呢 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
快速回复:谁能帮我看看错在哪呢 MAP容器问题
数据加载中...
 
   



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

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