4

我正在使用 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
4

1 回答 1

5

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

#include <hash_map>

stdext::hash_map<int, int> hm;

int main()
{
    return 0;
}

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

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

于 2013-01-14T23:45:12.977 回答