Solved

Question on hash_map in stl

Posted on 2003-10-27
6
1,271 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now