| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 546 人关注过本帖
标题:关于multimap问题
只看楼主 加入收藏
tfg0116
Rank: 1
等 级:新手上路
帖 子:44
专家分:0
注 册:2008-10-9
收藏
 问题点数:0 回复次数:0 
关于multimap问题
#include<iostream>
#include<vector>
#include<string>
#include<map>

using namespace std;

int main()
{
    multimap<string, string> authors;
    string author, work, searchItem;
    do
    {
    cout<<"Enter author:"<<endl;
    cin>>author;
    if(!cin)
        break;
    cout<<"Enter author's work"<<endl;
    while(cin>>work)
    authors.insert(make_pair(author, work));
    cin.clear();
    }while(cin);
    typedef multimap<string, string>::iterator itType;
    itType iter = authors.begin();
    if(iter == authors.end())
    {
        cout<<"empty multimap"<<endl;
        return 0;
    }
    string currAuthor, preAuthor;
    do
    {
        currAuthor = iter->first;
        if(preAuthor.empty() || currAuthor[0] != preAuthor[0])
            cout<<"Author Name Beginning with'"<<iter->first[0]<<"':"<<endl;
        cout<<currAuthor;
        pair<itType, itType> pos = authors.equal_range(iter->first);
        while(pos.first != pos.second)
        {
            cout<<", "<<pos.first->second;
            ++pos.first;
        }
        cout<<endl;
        iter = pos.second;
        preAuthor = currAuthor;
    }while(iter != authors.end());
    return 0;
}
加颜色的那行代码为什么可以这么写啊?iter是multimap<string, string>::iterator 类型,而pos.second是键currAuthor关联的最后一个实例的下一位置,这样赋值可以吗?
搜索更多相关主题的帖子: multimap 
2008-10-25 21:34
快速回复:关于multimap问题
数据加载中...
 
   



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

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