Avi Peretz
Avi Peretz

Reputation: 43

My attempt to define a hash_map variable is not working for me in VS2008

I'm using Visual Studio 2008. This is my code:

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

using namespace std;

hash_map <int, int> hm;

int main()
{
    return 0;
}

And here's my error:

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

Upvotes: 4

Views: 374

Answers (1)

GManNickG
GManNickG

Reputation: 504203

In the MSVC compiler, extensions to the standard library are placed in the stdext namespace:

#include <hash_map>

stdext::hash_map<int, int> hm;

int main()
{
    return 0;
}

Disclaimer: I don't own VS2008 but this should work. :)

Note, though, that you should update to the latest compiler if possible and use the new standard unordered containers instead: std::unordered_map and std::unordered_set.

Upvotes: 5

Related Questions