error C2784--------使用map遇到的小问题

来源:互联网 发布:男人心目中的女神 知乎 编辑:程序博客网 时间:2024/05/18 09:19

1、关于functional(86): error C2784

在使用map时,当键或值有string时,需要#include,千万不要写成#include "string.h"。否则会出现

xxxxxinclude\functional(86) : error C2784: 'bool __cdecl std::operator <(const class std::multimap<_K,Ty,_Pr,_A> &,const class std:: multimap<_K,_Ty,_Pr,_A> &)': could not deduce template argument for ' const class std::multimap<_K,_Ty,_Pr,_A> &' from 'const class std::basic_string,class std::allocator>'

.......


这样之类的错误

map中的key是默认以less<>序升序排列的,也就是说key本身要支持operator<,所以需要添加string头文件,大抵是因为里面包含了string类的各种操作。


2、关于#Include "String"和#Include "String.h"

C的标准库里已经有一个名字叫做“string.h”的头文件,包含一些常用的C字符串处理函数。

C++里则多了string这个头文件,里边有>和<等等操作,两者有不同的内容。


3、关于减少警告提示

#include 之前加上#pragma warning(disable:4786)可以减少使用map时产生的一些警告。

0 0
原创粉丝点击