Code:
#include <iostream>
#include <string>
using namespace std;
unsigned hash( const void* key, int len );
int main()
{
string text;
cout << "String: ";
cin >> text;
cout << "Hashed: " << hash( text.c_str(), text.length() );
cin.ignore();
return 0;
}
unsigned hash( const void* key, int len)
{
const unsigned char* p = (const unsigned char*)key;
unsigned h=0;
int i;
for(i=0; i<len; i++)
{
h=33*h+p[i];
}
return h;
}
Those are minimal changes to your code, take a close look and find out what has changed and why. Changes are in the function declaration, it now takes a const pointer, because aside from the compiler error, it's the correct way of doing stuff.