Std :: unordered_map uneclared 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; } 

I study and can not understand. The compiler throws an error that prints unordered_map, not declared.

I am using Visual C ++ 2008 Express Edition.

+4
source share
6 answers

In Visual Studio 2008, the classes in Technical Report 1 (TR1) are in the std :: tr1 namespace. Add:

 using namespace std::tr1; 

to your code.

+12
source

In TR1, unordered_map is accessible from the header file <tr1/unordered_map> as std::tr1::unordered_map .

In the next C ++ 0x standard, it is available from the <unordered_map> header file as std::unordered_map .

therefore you should use the header <tr1/unordered_map> and std::tr1::unordered_map namespace for vc 2008 because vc 2008 does not support C ++ 0x.

To answer the problem indicated in the comment.
Also, make sure you download the package for VS2008 !

Check out the list of supported new features.

 New containers (tuple, array, unordered set, etc) 
+7
source

Visual C ++ 2008 declares unordered_map in the std::tr1 namespace, not in std . See http://msdn.microsoft.com/en-us/library/bb982522(VS.90).aspx , Requirements section.

+4
source

Your code works in VS2010. With the release of TWO! if that's what you are not getting. Perhaps you should upgrade to VC ++ 2010 Express Edition.
Probably VC ++ 2008 does not include TR1

+2
source

In C ++ 03, unordered_map is defined in the std::tr1 namespace (if defined at all).

So you should use:

 std::tr1::unordered_map<int, std::string> m; 
+1
source

Perhaps you are looking for stdext::hash_map (included in <hash_map> ) instead?

VC ++ 2008, in my opinion, does not include TR1.

-1
source

All Articles