Solved

Question on hash_map in stl

Posted on 2003-10-27
6
1,262 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
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…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

707 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

21 Experts available now in Live!

Get 1:1 Help Now