We help IT Professionals succeed at work.

Hashtable equivalent in MFC C++

mdw233 asked
Medium Priority
Last Modified: 2013-12-14
Hi All,

I am looking for a fast data structure in c++.  I am currently storing data in a vector<CString> however any time I need to find a value I must traverse the entire vector until I find the specific value I am looking for.  In C# I am able to use a Hashtable to access the specific element I am looking for instantly, without traversing.  Does something like this exist in c++.  I have been playing around with stdext::hash_map<> but am not sure if it is my best option.  Not sure that it isn't either, but I am sort of a novice when it comes to c++ so I wanted to see if there was a better option.

As always, thanks in advance for any help!
Watch Question

CMap http://msdn.microsoft.com/en-us/library/s897094z(VS.80).aspx in MFC and hash_map http://msdn.microsoft.com/en-us/library/6x7w9f6z(VS.80).aspx are the most likely equivalents to the Hashtable in C#.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
The following data structure from the boost library might also be of interest http://www.boost.org/doc/libs/1_36_0/doc/html/boost/unordered_map.html
Top Expert 2012

I'd definitely prefer 'stdext::hash_map<>' over MFC's CMap if you explicity want a hash table.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.