Solved

Question on hash_map in stl

Posted on 2003-10-27
6
1,283 Views
Last Modified: 2013-12-14
I want to use a hash_map to store some data.  the key is going to be a const char* and the object is going to be a custom struct.  I have no idea how to go about implementing this and I can't find anything online.  I need to be pointed to a tutorial on using hash_maps.  the one on sgis website doesn't help enough.

I am trying to call the following:  

struct eqstr
      {
        bool operator()(const char* s1, const char* s2) const
      {
             return strcmp(s1, s2) == 0;
      }
      };
      hash_map<const char*, notes, hash<const char*>, eqstr> toolNotes;

and getting an error that hash is undefined.

0
Comment
Question by:jjacksn
6 Comments
 
LVL 9

Expert Comment

by:_ys_
ID: 9632954
Perhaps this is what you intended:

hash_map<const char*, notes, hash_compare<const char*, eqstr> > toolNotes;

Assuming that 'notes' is defined as a type (e.g. class notes).
0
 
LVL 5

Author Comment

by:jjacksn
ID: 9637317
Ok, that declaration works, but is says its deprecated.  Do you know of anywhere I can read about or see sample code of hash_map.  Not the sgi version, which is different.
0
 
LVL 15

Expert Comment

by:efn
ID: 9637812
There isn't any hash_map in the standard library, so implementations may vary.  Which one are you using?

This may help:

http://www.rpi.edu/~daiglm/plang/ml3.html

--efn
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Author Comment

by:jjacksn
ID: 9638502
I programming in VS.NET in C++.  STL doesn't have a hash_map?  I'm just using include <hash_map> Is there a better hash_map to use?
0
 
LVL 5

Author Comment

by:jjacksn
ID: 9638608
Basically, I want to do the following:

Using a custom deifnied struct, store information about users keyed on their e-mail addresses.  I will need to be accessing these over and over, updating the data, then finally outputing to an xml file.  What is the best/easiest way to do this.  I don't seem to be getting how use hashmap.
0
 
LVL 30

Accepted Solution

by:
Axter earned 200 total points
ID: 9638811
If you're using VC++ 7.1, hash_map is NOT in the std namespace.

They correctly moved it to stdext namespace instead.

VC++ 7.1 is one of the few compilers/libraries that were smart enough to put the hash_map out side of the std namespace.

If you're using VC++ 7.1, you  don't need to download anything.  It comes with the compiler.
Just make sure to use the right namespace.

stdext::hash_map<std::string, SalestInfo> contactList;
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
sorting efficency of sorting algorithm 30 129
trigs fail! I thought I knew how to do trignometry 3 82
Need some help with mailto 16 31
boost::uuid crashes 17 35
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand columnThat will then direct you to their download page.From that page s…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question