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())
所组成的区间。