-3

I need to use a dictionary that will map pairs of ints to a different pair of ints. Other SO questions on the topic claim that C++ has std::map and a hash_map, but for some reason my code doesn't seem to recognize it.

To try it out, I copied a random code I found:

hash_map<const char*, int, hash<const char*>, eqstr> months;

Visual Studio claims that: identifier "hash_map" is undefined

Any idea what it means, and how I could fix it? It's been a long time since I last used C++ so sorry if the question is basic... thanks.

Cheshie
  • 2,777
  • 6
  • 32
  • 51
  • "To try it out, I copied a random code I found" – oh yeah, that's not how programming works. – The Paramagnetic Croissant Mar 03 '15 at 12:00
  • 1
    Hey... what's wrong with that? When I use something for the first time, yeah, I copy some code, play around with it, and when I'm confident enough to use it I write stuff on my own. Is that so bad...? ;) – Cheshie Mar 03 '15 at 12:04

1 Answers1

2

hash_map is in the STL, an ancient library that formed the basis of the parts of the standard C++ library, but not in the standard library itself.

Since C++11, the standard library has a similar container called unordered_map.

Mike Seymour
  • 249,747
  • 28
  • 448
  • 644
  • OK... so I tried this: `std::unordered_map map;` and now I get: `std namespace has no member "ordered_map"`. Am I using it incorrectly? – Cheshie Mar 03 '15 at 12:01
  • 1
    @Cheshie: Did you `#include `? To learn about the standard library, you'd be better off with a [good book](http://stackoverflow.com/questions/388242) or [online reference](http://en.cppreference.com/w/cpp/container/unordered_map) rather than trying to compile random bits of code of dubious origin. – Mike Seymour Mar 03 '15 at 12:03
  • thanks for asking; no, I didn't (*embarrassing!*) :P Thank you! and thanks for the references. – Cheshie Mar 03 '15 at 12:07