您的位置:首页 > 编程语言 > C语言/C++

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

2014-06-10 01:50 183 查看


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时产生的一些警告。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  c++ map