c++ - 我尝试定义一个 hash_map 变量在 VS2008 中对我不起作用

标签 c++ visual-studio-2008 hashmap

我正在使用 Visual Studio 2008。这是我的代码:

#include "stdafx.h"
#include <conio.h>
#include <hash_map>
#include <iostream>

using namespace std;

hash_map <int, int> hm;

int main()
{
    return 0;
}

这是我的错误:

error C2143: syntax error : missing ';' before '<'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

最佳答案

在 MSVC 编译器中,对标准库的扩展放在 stdext 命名空间中:

#include <hash_map>

stdext::hash_map<int, int> hm;

int main()
{
    return 0;
}

免责声明:我没有 VS2008,但这应该可以。 :)

但请注意,如果可能,您应该更新到最新的编译器并改用新的标准无序容器:std::unordered_mapstd::unordered_set

关于c++ - 我尝试定义一个 hash_map 变量在 VS2008 中对我不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14328439/

相关文章:

c++ - 为什么我不能递减 std::array::end()?

C++套接字编程: maximize throughput/bandwidth on localhost (I only get 3 Gbit/s instead of 23GBit/s)

java - 使用对象列表作为字段覆盖类的哈希码方法

java - 为什么创建 HashMap 比创建 Object[] 更快?

java - 我应该使用哪种数据结构来表示这个数据集?

c++ - 内存地址可以存储为整数类型吗?

c++ - 将 header 添加到项目设置中的每个文件(gcc -include)

c# - 读取复杂的 XML 属性

c# - 无法加载一个或多个项目,但是VS却没有说是哪个

visual-studio-2008 - Visual SourceSafe 2005 与 VS2008 集成 - 缺少评论 checkin 提示