Question: 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: 
In C++03, `boost::hash`. In C++11, `std::hash`.

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

```
I encoutered the same question as you have, hope this code will help you :

```
int HashCode (const std::string &str) {
    int h = 0;
    for (size_t i = 0; i < str.size(); ++i)
        h = h * 31 + static_cast<int>(str[i]);
    return h;
}

```