vc2010 里地图的编译异常
vc2010 里map<string,int>的编译错误
C++ primary 第四版 关于map的下标操作有这么一样代码:
map<string,int> word_count;
string word;
while(cin >> word)
++word_count[word];
见312页,这里的map使用了下标作为键,并且可以查找,我依样画葫芦,写了以下代码:
string tempuser("1");
map<string,int> client;
client[tempuser] = 1;
结果编译失败,编译结果如下:
c:\program files (x86)\microsoft visual studio 10.0\vc\include\xfunctional(125): error C2784: “bool std::operator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)”: 未能从“const std::string”为“const std::_Tree<_Traits> &”推导 模板 参数
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\xtree(1885) : 参见“std::operator <”的声明
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\xfunctional(124): 编译类 模板 成员函数“bool std::less<_Ty>::operator ()(const _Ty &,const _Ty &) const”时
1> with
1> [
1> _Ty=std::string
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\map(71): 参见对正在编译的类 模板 实例化“std::less<_Ty>”的引用
1> with
1> [
1> _Ty=std::string
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\xtree(451): 参见对正在编译的类 模板 实例化“std::_Tmap_traits<_Kty,_Ty,_Pr,_Alloc,_Mfl>”的引用
1> with
1> [
1> _Kty=std::string,
1> _Ty=SOCKET,
1> _Pr=std::less<std::string>,
1> _Alloc=std::allocator<std::pair<const std::string,SOCKET>>,
C++ primary 第四版 关于map的下标操作有这么一样代码:
map<string,int> word_count;
string word;
while(cin >> word)
++word_count[word];
见312页,这里的map使用了下标作为键,并且可以查找,我依样画葫芦,写了以下代码:
string tempuser("1");
map<string,int> client;
client[tempuser] = 1;
结果编译失败,编译结果如下:
c:\program files (x86)\microsoft visual studio 10.0\vc\include\xfunctional(125): error C2784: “bool std::operator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)”: 未能从“const std::string”为“const std::_Tree<_Traits> &”推导 模板 参数
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\xtree(1885) : 参见“std::operator <”的声明
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\xfunctional(124): 编译类 模板 成员函数“bool std::less<_Ty>::operator ()(const _Ty &,const _Ty &) const”时
1> with
1> [
1> _Ty=std::string
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\map(71): 参见对正在编译的类 模板 实例化“std::less<_Ty>”的引用
1> with
1> [
1> _Ty=std::string
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\xtree(451): 参见对正在编译的类 模板 实例化“std::_Tmap_traits<_Kty,_Ty,_Pr,_Alloc,_Mfl>”的引用
1> with
1> [
1> _Kty=std::string,
1> _Ty=SOCKET,
1> _Pr=std::less<std::string>,
1> _Alloc=std::allocator<std::pair<const std::string,SOCKET>>,