map初始化为什么会出这样的错?

big_cucumber big_cucumber 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
代码如下:

#include "stdafx.h"
#include <map>
using namespace std;


int _tmain(int argc, _TCHAR* argv[])
{
map<string, int> mymap;

string str = "123";
int temp = 1;
mymap[str] = temp;
//mymap.insert(pair<string, int>(str, temp));

return 0;
}


编译错误:
1>正在编译...
1>as.cpp
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\functional(143) : 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 9.0\vc\include\xtree(1466) : 参见“std::operator <”的声明
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\functional(142): 编译类 模板 成员函数“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 9.0\vc\include\map(68): 参见对正在编译的类 模板 实例化“std::less<_Ty>”的引用
1> with
1> [
1> _Ty=std::string
1> ]
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\xtree(22): 参见对正在编译的类 模板 实例化“std::_Tmap_traits<_Kty,_Ty,_Pr,_Alloc,_Mfl>”的引用
1> with
1> [
1> _Kty=std::string,
1> _Ty=int,
1> _Pr=std::less<std::string>,
1> _Alloc=std::allocator<std::pair<const std::string,int>>,
1> _Mfl=false
1> ]
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\xtree(63): 参见对正在编译的类 模板 实例化“std::_Tree_nod<_Traits>”的引用
1> with
1> [
1> _Traits=std::_Tmap_traits<std::string,int,std::less<std::string>,std::allocator<std::pair<const std::string,int>>,false>
1> ]
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\xtree(89): 参见对正在编译的类 模板 实例化“std::_Tree_ptr<_Traits>”的引用
1> with
1> [
1> _Traits=std::_Tmap_traits<std::string,int,std::less<std::string>,std::allocator<std::pair<const std::string,int>>,false>
1> ]
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\xtree(107): 参见对正在编译的类 模板 实例化“std::_Tree_val<_Traits>”的引用
1> with
1> [
1> _Traits=std::_Tmap_traits<std::string,int,std::less<std::string>,std::allocator<std::pair<const std::string,int>>,false>
1> ]
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\map(78): 参见对正在编译的类 模板 实例化“std::_Tree<_Traits>”的引用
1> with
1> [
1> _Traits=std::_Tmap_traits<std::string,int,std::less<std::string>,std::allocator<std::pair<const std::string,int>>,false>
1> ]
1> e:\projects\as\as.cpp(11): 参见对正在编译的类 模板 实例化“std::map<_Kty,_Ty>”的引用
1> with
1> [
1> _Kty=std::string,
1> _Ty=int
1> ]
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\functional(143) : 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 9.0\vc\include\xtree(1466) : 参见“std::operator <”的声明
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\functional(143) : 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 9.0\vc\include\xtree(1466) : 参见“std::operator <”的声明
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\functional(143) : 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 9.0\vc\include\xtree(1466) : 参见“std::operator <”的声明
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\functional(143) : error C2784: “bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)”: 无法从“const std::string”为“const std::reverse_iterator<_RanIt> &”推导 模板 参数
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\xutility(2236) : 参见“std::operator <”的声明
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\functional(143) : error C2784: “bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)”: 无法从“const std::string”为“const std::reverse_iterator<_RanIt> &”推导 模板 参数
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\xutility(2236) : 参见“std::operator <”的声明
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\functional(143) : error C2784: “bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)”: 无法从“const std::string”为“const std::reverse_iterator<_RanIt> &”推导 模板 参数
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\xutility(2236) : 参见“std::operator <”的声明
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\functional(143) : error C2784: “bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)”: 无法从“const std::string”为“const std::reverse_iterator<_RanIt> &”推导 模板 参数
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\xutility(2236) : 参见“std::operator <”的声明
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\functional(143) : error C2784: “bool std::operator <(const std::_Revranit<_RanIt,_Base> &,const std::_Revranit<_RanIt2,_Base2> &)”: 无法从“const std::string”为“const std::_Revranit<_RanIt,_Base> &”推导 模板 参数
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\xutility(2046) : 参见“std::operator <”的声明
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\functional(143) : error C2784: “bool std::operator <(const std::_Revranit<_RanIt,_Base> &,const std::_Revranit<_RanIt2,_Base2> &)”: 无法从“const std::string”为“const std::_Revranit<_RanIt,_Base> &”推导 模板 参数
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\xutility(2046) : 参见“std::operator <”的声明
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\functional(143) : error C2784: “bool std::operator <(const std::_Revranit<_RanIt,_Base> &,const std::_Revranit<_RanIt2,_Base2> &)”: 无法从“const std::string”为“const std::_Revranit<_RanIt,_Base> &”推导 模板 参数
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\xutility(2046) : 参见“std::operator <”的声明
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\functional(143) : error C2784: “bool std::operator <(const std::_Revranit<_RanIt,_Base> &,const std::_Revranit<_RanIt2,_Base2> &)”: 无法从“const std::string”为“const std::_Revranit<_RanIt,_Base> &”推导 模板 参数
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\xutility(2046) : 参见“std::operator <”的声明
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\functional(143) : error C2784: “bool std::operator <(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)”: 无法从“const std::string”为“const std::pair<_Ty1,_Ty2> &”推导 模板 参数
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\utility(84) : 参见“std::operator <”的声明
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\functional(143) : error C2784: “bool std::operator <(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)”: 无法从“const std::string”为“const std::pair<_Ty1,_Ty2> &”推导 模板 参数
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\utility(84) : 参见“std::operator <”的声明
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\functional(143) : error C2784: “bool std::operator <(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)”: 无法从“const std::string”为“const std::pair<_Ty1,_Ty2> &”推导 模板 参数
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\utility(84) : 参见“std::operator <”的声明
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\functional(143) : error C2784: “bool std::operator <(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)”: 无法从“const std::string”为“const std::pair<_Ty1,_Ty2> &”推导 模板 参数
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\utility(84) : 参见“std::operator <”的声明
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\functional(143) : error C2676: 二进制“<”: “const std::string”不定义该运算符或到预定义运算符可接收的类型的转换
1>生成日志保存在“file://e:\Projects\as\Debug\BuildLog.htm”
1>as - 17 个错误,0 个警告
...全文

相关推荐

评论 3
收藏 已收藏
分享
返回顶部
big_cucumber
C++ 语言 65,214 成员 250,514 内容