C
Charles Herman
I have the folowing program:
#include <iostream>
#include <ext/hash_map>
using namespace std;
using namespace __gnu_cxx;
typedef hash_map<char*, long, hash<char*> > char_hash_t;
typedef hash_map<char*, long, hash<char*> >::value_type char_pair_t;
int main()
{
char key[100];
char_hash_t ht;
for (long i = 0; i < 10; ++i)
{
sprintf (key, "%lld", 23*i);
ht.insert( char_pair_t ( key, i ));
}
char_hash_t::iterator p;
for (p = ht.begin(); p != ht.end(); ++p)
cout << "key = " << p->first
<< " val = " << p->second << endl;
return 0;
}
When I run it, it prints the line
key = 207 val = 7
then goes into an infinite loop printing out the line
key = 207 val = 8
until I hit ctrl-c.
Can anyone see a problem with it? It looks perfectly good to me.
-charles
#include <iostream>
#include <ext/hash_map>
using namespace std;
using namespace __gnu_cxx;
typedef hash_map<char*, long, hash<char*> > char_hash_t;
typedef hash_map<char*, long, hash<char*> >::value_type char_pair_t;
int main()
{
char key[100];
char_hash_t ht;
for (long i = 0; i < 10; ++i)
{
sprintf (key, "%lld", 23*i);
ht.insert( char_pair_t ( key, i ));
}
char_hash_t::iterator p;
for (p = ht.begin(); p != ht.end(); ++p)
cout << "key = " << p->first
<< " val = " << p->second << endl;
return 0;
}
When I run it, it prints the line
key = 207 val = 7
then goes into an infinite loop printing out the line
key = 207 val = 8
until I hit ctrl-c.
Can anyone see a problem with it? It looks perfectly good to me.
-charles