1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
#include <iostream>
#include <map>
using namespace std;
int main()
{ multimap<string,int> mymap;
multimap<string,int>::iterator iter;
pair<multimap<char,int>::iterator, multimap<char,int>::iterator> par;
mymap.insert(pair<char,int>('a',8));
mymap.insert(pair<char,int>('b',10));
mymap.insert(pair<char,int>('b',990));
mymap.insert(pair<char,int>('c',69));
mymap.insert(pair<char,int>('d',89));
mymap.insert(pair<char,int>('d',39));
mymap.insert(pair<char,int>('e',89));
mymap.insert(pair<char,int>('f',1));
cout<<"the map contains"<<endl;
for(char ch='a';ch<='f';ch++)
{
cout << ch << " =>";
par = mymap.equal_range(ch);
for (iter=par.first; iter!=par.second; ++iter)
cout << " " << (*iter).second;
cout << " "<<endl;
}
system("pause");
return 0;
}
|
I don't know why the compiler said that:
No constructor could take the source type, or constructor overload resolution was ambiguous
1>c:\users\danny\documents\visual studio 2010\projects\mutimap\mutimap\main.cpp(23): error C2275: 'par' : illegal use of this type as an expression
1> c:\users\danny\documents\visual studio 2010\projects\mutimap\mutimap\main.cpp(7) : see declaration of 'par'
1>c:\users\danny\documents\visual studio 2010\projects\mutimap\mutimap\main.cpp(23): error C2228: left of '.first' must have class/struct/union
1>c:\users\danny\documents\visual studio 2010\projects\mutimap\mutimap\main.cpp(23): error C2275: 'par' : illegal use of this type as an expression
1> c:\users\danny\documents\visual studio 2010\projects\mutimap\mutimap\main.cpp(7) : see declaration of 'par'
1>c:\users\danny\documents\visual studio 2010\projects\mutimap\mutimap\main.cpp(23): error C2228: left of '.second' must have class/struct/union
1>c:\users\danny\documents\visual studio 2010\projects\mutimap\mutimap\main.cpp(61): error C2059: syntax error : '}'
1>c:\users\danny\documents\visual studio 2010\projects\mutimap\mutimap\main.cpp(61): error C2143: syntax error : missing ';' before '}'
1>c:\users\danny\documents\visual studio 2010\projects\mutimap\mutimap\main.cpp(61): error C2059: syntax error : '}'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========