通过map.equal_range发出interator

时间:2013-01-18 18:47:58

标签: c++ iterator key multimap

当我使用map.equal_range()时,我有问题迭代地图。我编译器说没有 's_it = Krange.std :: pair<>中的'operator ='不匹配并且不匹配'operator!='?? 我很困惑,无法弄清楚为什么 以下是我的代码

void Pdb2Cluster_test
(
    multimap <string, unsigned> & pigAccmap,
    multimap <unsigned, proteininfo> & map2
)
{
    // CArgs args = GetArgs();
    //AnsiString v = diff_b;
    multimap<string , unsigned>::iterator imp;

    multimap<string,proteininfo>::iterator s_it;
    multimap<string, pdbbinfo>::iterator ip;
    // set<string>::iterator idp;
    unsigned pig_b;
    int start, stop;
    // int mststar, mstto;
    unsigned cluster, domgi;
    string pdb_ele;


    pdb_ele = "3ST9A";

    imp = pigAccmap.find(pdb_ele);
    if (imp != pigAccmap.end())
    {    pig_b = imp->second;

        std::pair<multimap<unsigned, proteininfo>::iterator, multimap<unsigned,proteininfo>::iterator> Krange;
        Krange  = map2.equal_range(pig_b);
        for (s_it = Krange.first; s_it != Krange.second; s_it++)
        {
            domgi= s_it->second.domgi;
            start= s_it->second.seqstar;
            stop= s_it->second.seqstop;
            cout<<"\t"<<cluster<<"\t"<<pdb_ele<<"\t" <<pig_b<<"\t"<<domgi<<"\t"<<start<<"\t"<<stop<<endl;
            //   myfile<<cluster<<"\t"<<pdb_ele<<"\t" <<domgi<<"\t"<<start<<"\t"<<stop<<endl;

        }
        imp++;
    }
}

我只需要迭代第二个多图,所以忽略第一个循环的map.find() 我提到http://www.cplusplus.com/reference/map/multimap/equal_range/ ....

1 个答案:

答案 0 :(得分:1)

map2的类型为std::multimap<unsigned, proteininfo>

s_it的类型为std::multimap<std::string, proteininfo>::iterator

这些不匹配。

使用某些typedef可能会省去一些麻烦,比如

typedef std::multimap<std::string, proteininfo> protein_map_type;