首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

C++关联容器,map的使用,插入元素,该怎么解决

2012-04-17 
C++关联容器,map的使用,插入元素C/C++ codemapstring, int word_count//word_count.insert(make_pair(

C++关联容器,map的使用,插入元素

C/C++ code
    map<string, int> word_count;    //word_count.insert(make_pair("ss", 1232));    //word_count.insert(make_pair("qq", 322));    word_count.insert(map<string, int>::value_type("ss", 123));


就这么简单的使用,怎么出来一大堆错误呢?刚学STL


错误1error C2784: “bool std::operator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)”: 未能从“const std::string”为“const std::_Tree<_Traits> &”推导 模板 参数c:\program files (x86)\microsoft visual studio 10.0\vc\include\xfunctional125
错误2error C2784: “bool std::operator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)”: 未能从“const std::string”为“const std::_Tree<_Traits> &”推导 模板 参数c:\program files (x86)\microsoft visual studio 10.0\vc\include\xfunctional125
错误3error C2784: “bool std::operator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)”: 未能从“const std::string”为“const std::_Tree<_Traits> &”推导 模板 参数c:\program files (x86)\microsoft visual studio 10.0\vc\include\xfunctional125
错误4error C2784: “bool std::operator <(const std::unique_ptr<_Ty,_Dx> &,const std::unique_ptr<_Ty2,_Dx2> &)”: 未能从“const std::string”为“const std::unique_ptr<_Ty,_Dx> &”推导 模板 参数c:\program files (x86)\microsoft visual studio 10.0\vc\include\xfunctional125
错误5error C2784: “bool std::operator <(const std::unique_ptr<_Ty,_Dx> &,const std::unique_ptr<_Ty2,_Dx2> &)”: 未能从“const std::string”为“const std::unique_ptr<_Ty,_Dx> &”推导 模板 参数c:\program files (x86)\microsoft visual studio 10.0\vc\include\xfunctional125
错误6error C2784: “bool std::operator <(const std::unique_ptr<_Ty,_Dx> &,const std::unique_ptr<_Ty2,_Dx2> &)”: 未能从“const std::string”为“const std::unique_ptr<_Ty,_Dx> &”推导 模板 参数c:\program files (x86)\microsoft visual studio 10.0\vc\include\xfunctional125
错误7error C2784: “bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)”: 未能从“const std::string”为“const std::reverse_iterator<_RanIt> &”推导 模板 参数c:\program files (x86)\microsoft visual studio 10.0\vc\include\xfunctional125
错误8error C2784: “bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)”: 未能从“const std::string”为“const std::reverse_iterator<_RanIt> &”推导 模板 参数c:\program files (x86)\microsoft visual studio 10.0\vc\include\xfunctional125
错误9error C2784: “bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)”: 未能从“const std::string”为“const std::reverse_iterator<_RanIt> &”推导 模板 参数c:\program files (x86)\microsoft visual studio 10.0\vc\include\xfunctional125
错误10error C2784: “bool std::operator <(const std::_Revranit<_RanIt,_Base> &,const std::_Revranit<_RanIt2,_Base2> &)”: 未能从“const std::string”为“const std::_Revranit<_RanIt,_Base> &”推导 模板 参数c:\program files (x86)\microsoft visual studio 10.0\vc\include\xfunctional125
错误11error C2784: “bool std::operator <(const std::_Revranit<_RanIt,_Base> &,const std::_Revranit<_RanIt2,_Base2> &)”: 未能从“const std::string”为“const std::_Revranit<_RanIt,_Base> &”推导 模板 参数c:\program files (x86)\microsoft visual studio 10.0\vc\include\xfunctional125
错误12error C2784: “bool std::operator <(const std::_Revranit<_RanIt,_Base> &,const std::_Revranit<_RanIt2,_Base2> &)”: 未能从“const std::string”为“const std::_Revranit<_RanIt,_Base> &”推导 模板 参数c:\program files (x86)\microsoft visual studio 10.0\vc\include\xfunctional125
错误13error C2784: “bool std::operator <(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)”: 未能从“const std::string”为“const std::pair<_Ty1,_Ty2> &”推导 模板 参数c:\program files (x86)\microsoft visual studio 10.0\vc\include\xfunctional125


错误14error C2784: “bool std::operator <(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)”: 未能从“const std::string”为“const std::pair<_Ty1,_Ty2> &”推导 模板 参数c:\program files (x86)\microsoft visual studio 10.0\vc\include\xfunctional125
错误15error C2784: “bool std::operator <(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)”: 未能从“const std::string”为“const std::pair<_Ty1,_Ty2> &”推导 模板 参数c:\program files (x86)\microsoft visual studio 10.0\vc\include\xfunctional125
错误16error C2676: 二进制“<”:“const std::string”不定义该运算符或到预定义运算符可接收的类型的转换c:\program files (x86)\microsoft visual studio 10.0\vc\include\xfunctional125


map<int, int>就没事


[解决办法]
lz用的什么编译器?
g++4.6.1
vs2008
都编译通过.
如果是 vc6.0,请换一个,那个对模板支持不够
[解决办法]
首先包含头文件
#include <string>
#include <map>

using namespace std;

如下写法均合法:
map<string, int> word_count;
word_count["string_1"] = 1;
word_count.insert(make_pair<string, int>("string_2", 2));
word_count.insert(map<string, int>::value_type("string_3", 3));

在Visual Studio 2010中编译通过。
[解决办法]
至少要熟悉吧,有时间就深入学习,可以看看候杰的 <STL源码剖析>

[解决办法]
stl 可以一边看源码剖析, 一边对着源码看,,,很爽的
[解决办法]

探讨
VS2010比较vs2005, 有哪些优点,好处?

热点排行