C++ STL 中map的value_comp问题。 10
#include<iostream>#include<cstdlib>#include<string>#include<map>#include"print.h"usin...
#include <iostream>
#include <cstdlib>
#include <string>
#include <map>
#include "print.h"
using namespace std;
int main()
{
map<int,string> t;
t[1] = "January";
t[2] = "February";
t[3] = "March";
t[4] = "April";
t[5] = "May";
t[6] = "June";
t[7] = "July";
t[8] = "August";
t[9] = "September";
t[10] = "October";
t[11] = "November";
t[12] = "December";
string t1 = "July" , t2 = "May";
map<int,string>::key_compare mycomp = t.key_comp();
map<int,string>::value_compare myvcomp = t.value_comp();
cout << t.at(1) << endl;
out();
cout << boolalpha << mycomp(1,5) << endl;
cout << myvcomp(“Octorber”,"December") << endl;
//为什么这一句会出错呢???
out();
for(int i = 1;i < 13;i++)
cout << t[i] << endl;
cout << t[1] << endl;
return 0;
}
map.cpp:30:39: error: no match for call to '(std::map<int, std::basic_string<cha
r> >::value_compare) (const char [9], const char [9])'
cout << myvcomp("December","December") << endl;
^
In file included from d:\program\g++\lib\gcc\mingw32\4.8.1\include\c++\map:61:0,
from map.cpp:4:
d:\program\g++\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_map.h:114:13: note: ca
ndidate is:
class value_compare
^ 展开
#include <cstdlib>
#include <string>
#include <map>
#include "print.h"
using namespace std;
int main()
{
map<int,string> t;
t[1] = "January";
t[2] = "February";
t[3] = "March";
t[4] = "April";
t[5] = "May";
t[6] = "June";
t[7] = "July";
t[8] = "August";
t[9] = "September";
t[10] = "October";
t[11] = "November";
t[12] = "December";
string t1 = "July" , t2 = "May";
map<int,string>::key_compare mycomp = t.key_comp();
map<int,string>::value_compare myvcomp = t.value_comp();
cout << t.at(1) << endl;
out();
cout << boolalpha << mycomp(1,5) << endl;
cout << myvcomp(“Octorber”,"December") << endl;
//为什么这一句会出错呢???
out();
for(int i = 1;i < 13;i++)
cout << t[i] << endl;
cout << t[1] << endl;
return 0;
}
map.cpp:30:39: error: no match for call to '(std::map<int, std::basic_string<cha
r> >::value_compare) (const char [9], const char [9])'
cout << myvcomp("December","December") << endl;
^
In file included from d:\program\g++\lib\gcc\mingw32\4.8.1\include\c++\map:61:0,
from map.cpp:4:
d:\program\g++\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_map.h:114:13: note: ca
ndidate is:
class value_compare
^ 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询