std::使用Visual C++2008映射未声明的标识符
std::unordered_map undeclared identifier using Visual C++ 2008
#include <iostream>
#include <string>
#include <unordered_map>
using namespace std;
int main()
{
unordered_map< int, string > m;
m[1] = "one";
m[2] = "two";
m[4] = "four";
m[3] = "three";
m[2] = "TWO!";
cout << m[2] << endl;
m.clear();
return 0;
}
我在学习,却搞不明白。编译器抛出类型unordered_map
未声明的错误。
我使用的是Visual C++2008速成版。
在Visual Studio 2008中,技术报告1(TR1(中的类位于命名空间std::TR1中。添加:
using namespace std::tr1;
到您的代码。
在TR1中,unordered_map
可作为std::tr1::unordered_map
从<tr1/unordered_map>
头文件中获得。
在即将推出的C++0x标准中,它可以从<unordered_map>
头文件中作为std::unordered_map
获得。
因此您应该为vc 2008使用<tr1/unordered_map>
标头和std::tr1::unordered_map
命名空间,因为vc 2008不支持C++0x。
回答你在评论中引用的问题
此外,请确保下载VS2008的功能包!
在支持的新功能列表下进行检查。
New containers (tuple, array, unordered set, etc)
std::tr1
中声明了unordered_map
,而不是在std
中。看见http://msdn.microsoft.com/en-us/library/bb982522(VS.90(.aspx,要求一节。
您的代码在VS2010中按预期工作。输出两个!如果这是你没有得到的。可能您应该切换到VC++2010速成版
可能VC++2008不包括TR1
在C++03中,unordered_map
是在std::tr1
命名空间中定义的(如果已经定义的话(。
所以你应该使用:
std::tr1::unordered_map<int, std::string> m;
也许您正在寻找stdext::hash_map
(包含在<hash_map>
中(?
据我所知,VC++2008表达不包括TR1。
相关文章:
- 在顶点着色器中使用 OpenGl 的未声明标识符,我在顶点着色器中绘制三角形时遇到问题
- Google protobuf 时间戳未声明标识符,在 Windows 上具有C++
- 我的函数调用 (C++) 中的未声明标识符
- 具有继承的未声明标识符(运算符 ostream)
- 无法确定 IDE 在 C++ 中说出未声明标识符的原因
- 错误 C2065:'lO':用于声明向量值的未声明标识符?
- 可变参数模板的未声明标识符
- 动态变量上的c++MACRO未声明标识符
- 指向对象的指针的未声明标识符向量
- 简单C++程序上的多个未声明标识符
- C++类"未声明标识符"
- 计算文本文件中的整数数(使用 fin>>x 的未声明标识符)
- 编译器错误 xcode 未声明标识符 C++
- 直接 X 11 纹理 FX 文件错误 X3004 未声明标识符"input"
- GCC 未声明标识符"_asm"
- ios_base类的C++未声明标识符
- 未声明标识符SQL_SS_TABLE
- 使用arrayfire的未声明标识符
- 未声明标识符和标识符未定义是什么意思?如何修复错误
- 在 MacOS 上使用 OpenMPI C++语法时未声明标识符'MPI'