how to get hash code of a string in c++

sufyan siddique picture sufyan siddique · Nov 11, 2011 · Viewed 63.6k times · Source

Following java code returns hash code of a string.

String uri = "Some URI"
public int hashCode() {
    return uri.hashCode();
}

I want to translate this code to c++. Is there any function availabe in c++ or an easy way to translate this.

Answer

Cat Plus Plus picture Cat Plus Plus · Nov 11, 2011

In C++03, boost::hash. In C++11, std::hash.

std::hash<std::string>()("foo");