Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Question on hash_map in stl

Posted on 2003-10-27
6
1,282 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying 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
c++ syntax question 9 52
egit plugin on eclipse 8 82
VS2015 Redefinition errors 4 70
Best environment for cross platform web development? 5 54
  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 …
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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 clear a vector as well as how to detect empty vectors in C++.

829 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