使用make_pair报错

使用make_pair报错

题目
使用make_pair报错
当使用,并将其参数用作字符串时,编译就会报错.例如:
mapcoll;
coll.insert(make_pair("zxr","xh"))
当然我在程序顶端包含了string,map,也写了using namespace std;
错误提示如下:f:\microsoft visual studio\vc98\include\utility(21) :error C2536:'std::pair::first' :cannot specify explicit initializer for arrays
f:\microsoft visual studio\vc98\include\utility(25) :see declaration of 'first'
f:\microsoft visual studio\vc98\include\utility(21) :while compiling class-template member function '__thiscall std::pair::std::pair(const char (&)[4],const char (&)[3])'
f:\microsoft visual studio\vc98\include\utility(21) :error C2536:'std::pair::second' :cannot specify explicit initializer for arrays
f:\microsoft visual studio\vc98\include\utility(26) :see declaration of 'second'
f:\microsoft visual studio\vc98\include\utility(21) :while compiling class-template member function '__thiscall std::pair::std::pair(const char (&)[4],const char (&)[3])'
错误指示:
#ifdef _MSC_VER
#pragma pack(push,8)
#endif /* _MSC_VER */
_STD_BEGIN
// TEMPLATE STRUCT pair
template struct pair {
typedef _T1 first_type;
typedef _T2 second_type;
pair()
:first(_T1()),second(_T2()) {}
pair(const _T1& _V1,const _T2& _V2)
:first(_V1),second(_V2) {}
template pair(const pair &p)
:first(p.first),second(p.second) {}
_T1 first;
_T2 second;
};
答案
改成:coll.insert(make_pair(string("zxr"),string("xh")))
举一反三
已知函数f(x)=x,g(x)=alnx,a∈R.若曲线y=f(x)与曲线y=g(x)相交,且在交点处有相同的切线,求a的值和该切线方程.
我想写一篇关于奥巴马的演讲的文章,写哪一篇好呢?为什么好
奥巴马演讲不用看稿子.为什么中国领导演讲要看?
想找英语初三上学期的首字母填空练习……
英语翻译
最新试题
热门考点

超级试练试题库

© 2017-2019 超级试练试题库,All Rights Reserved.