gcc中使用hash_map事例

28 views
Skip to first unread message
Message has been deleted

bruc...@gmail.com

unread,
Apr 5, 2006, 12:15:01 AM4/5/06
to 星星爱CPP
#include <iostream>
#include <string>
#include <ext/hash_map>
using namespace std;
using namespace __gnu_cxx;

namespace __gnu_cxx
{
template<> struct hash<const string>
{
size_t operator()(const string& s) const
{ return hash<const char*>()( s.c_str() ); } //
__stl_hash_string
};
template<> struct hash<string>
{
size_t operator()(const string& s) const
{ return hash<const char*>()( s.c_str() ); }
};
}

int main( void )
{
hash_map<string,int> test;
test["abc"] = 1;
cout << test["abc"] << endl;
system( "pause" );
}

---

Reply all
Reply to author
Forward
0 new messages