hash_map<string,int>

Write here if you have problems with your C++ source code

Moderator: Board moderators

Post Reply
jan_holmes
Experienced poster
Posts: 136
Joined: Fri Apr 15, 2005 3:47 pm
Location: Singapore
Contact:

hash_map<string,int>

Post by jan_holmes » Sat Dec 02, 2006 1:57 pm

I'm trying to solve a problem by implementing hash_map<string,int> stl in my program. But I got Compile Error many times.

This is the header that might result that compile error :

Code: Select all

#include <iostream>
#include <bitset>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <cctype>
#include <set>
#include <cmath>
#include <climits>
#include <sstream>
#include <list>
#include <functional>
#include <utility>
#include <iomanip>
#include <ctime>
#include <ext/hash_map>


using namespace std;
using namespace __gnu_cxx;


namespace __gnu_cxx {
	template<> struct hash< std::string >{
		size_t operator()( const std::string& x ) const{
			return hash< const char* >()( x.c_str() );
		}
	};
}
Anyone can help ? Thx... :D

User avatar
Krzysztof Duleba
Guru
Posts: 584
Joined: Thu Jun 19, 2003 3:48 am
Location: Sanok, Poland
Contact:

Post by Krzysztof Duleba » Sat Dec 02, 2006 2:41 pm

The error message you're getting should be very straightforward, what part of it do you need help with?

Hint: hash_* aren't portable, so don't be surprised that you have to use a particular version of gcc to reproduce OJ's behaviour.
For millions of years, mankind lived just like the animals. Then something happened which unleashed the power of our imagination. We learned to talk and we learned to listen...

jan_holmes
Experienced poster
Posts: 136
Joined: Fri Apr 15, 2005 3:47 pm
Location: Singapore
Contact:

Post by jan_holmes » Sat Dec 02, 2006 5:41 pm

thx for the explanation !!! :D

DD
Experienced poster
Posts: 145
Joined: Thu Aug 14, 2003 8:42 am
Location: Mountain View, California
Contact:

Re: hash_map<string,int>

Post by DD » Tue Mar 29, 2011 6:48 am

You can the unordered_map in TR1 instead. It is convenient and easy to use. :)
Have you ever...
  • Wanted to work at best companies?
  • Struggled with interview problems that could be solved in 15 minutes?
  • Wished you could study real-world problems?
If so, you need to read Elements of Programming Interviews.

Post Reply

Return to “C++”