我正在使用 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_map
和 std::unordered_set
。
关于c++ - 我尝试定义一个 hash_map 变量在 VS2008 中对我不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14328439/