23
In C++03, boost::hash. In C++11, std::hash.
std::hash<std::string>()("foo");
The following is the source for the default String.hashCode() in Java, this is a trival exercise to implement in C++.
public int hashCode()
{
int h = hash;
if (h == 0 && count > 0)
{
int off = offset;
char val[] = value;
int len = count;
for (int i = 0; i < len; i++)
{
h = 31*h + val[off++];
}
hash = h;
}
return h;
}