在文件example.cc中有如下关于m1的定义:
//文件example.cc
#include <string>
#include <iostream>
#include <map>
using namespace std;
multimap<string,int> m1{
{"str1",1},{"str1",2},{"str1",3},{"str1",4},{"str1",5},{"str1",6}};
现在来查找m1中关键字等于"str1"的值分别是多少.
方法1:
#include <string>
#include <iostream>
#include <map>
#include "example.cc"
using namespace std;
int main()
{
multimap<string,int>::iterator it = m1.find("str1");
int cnt = m1.count("str1");
int i = 0;
for(i = 0;i != cnt; ++i)
{
cout << it->second << endl;
it ++;
}
方法2:
#include <string>
#include <iostream>
#include <set>
#in