首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

multimap的查询有关问题

2012-04-11 
multimap的查询问题#includemain.h structTest{stringnameinti}templateclassTstructm_less:public

multimap的查询问题
#include   "main.h "

struct   Test
{
string   name;
int   i;
};


template   <class   T>
struct   m_less   :   public   binary_function <T,   T,   bool   >
{
bool   operator()(const   T   lhs,   const   T   rhs)   const
{
return   lhs.name   <   rhs.name   ||   (lhs.name   ==   rhs.name   &&   lhs.i   <   rhs.i);
}  
};

void   main()
{

multimap <Test,   int,   less <Test>   >   MMap;
pair <Test,   int>   P;
P.first.name   =   "a ";
P.first.i   =   0;
P.second   =   10;
MMap.insert(P);

P.first.name   =   "a ";
P.first.i   =   1;
P.second   =   11;
MMap.insert(P);

P.first.name   =   "a ";
P.first.i   =   2;
P.second   =   12;
MMap.insert(P);

multimap <Test,   int,   less <Test>   > ::iterator   itor;

//     该如何实现?    
itor   =   MMap.find( "a ");
//
while(   itor!=MMap.end()   )
{
cout   < <   itor-> second;
itor++;
}
system( "pause ");
}

谢谢!!!

[解决办法]
当然,使用一些变通也可以
lower_bound(name,numeric_limits <int> ::min())
upper_bound(name, numeric_limits <int> ::max())
所组成的区间。

热点排行