multimap 一对多。。给力啊
View Code
// multimap::lower_bound/upper_bound #include <iostream> #include <map> using namespace std; int main () { multimap<char,int> mymultimap; multimap<char,int>::iterator it,itlow,itup; mymultimap.insert(pair<char,int>('a',10)); mymultimap.insert(pair<char,int>('b',121)); mymultimap.insert(pair<char,int>('c',1001)); mymultimap.insert(pair<char,int>('c',2002)); mymultimap.insert(pair<char,int>('d',11011)); mymultimap.insert(pair<char,int>('e',44)); itlow=mymultimap.lower_bound ('b'); // itlow points to b itup=mymultimap.upper_bound ('d'); // itup points to e (not d) // print range [itlow,itup): for ( it=itlow ; it != itup; it++ ) cout << (*it).first << " => " << (*it).second << endl; return 0; }
#include <iostream> #include <map> using namespace std; int main () { multimap<char,int> mymultimap; multimap<char,int>::iterator it, its; // first insert function version (single parameter): mymultimap.insert ( pair<char,int>('a',100) ); mymultimap.insert ( pair<char,int>('z',150) ); mymultimap.insert ( pair<char,int>('a',120) ); /* while( ( it = mymultimap.find( 'a' ) ) != mymultimap.end() ) { printf("%c %d\n",it->first,it->second); //mymulti; } */ it = mymultimap.lower_bound('a'); its = mymultimap.upper_bound('a'); for( ; it != its; it++) printf("%c %d\n",it->first,it->second); // showing contents: cout << "mymultimap contains:\n"; for ( it=mymultimap.begin() ; it != mymultimap.end(); it++ ) cout << (*it).first << " => " << (*it).second << endl; system("pause"); return 0; }
posted on 2012-08-06 09:13 more think, more gains 阅读(234) 评论(0) 编辑 收藏 举报