How can I hash a string to an int using c++?

前端 未结 10 1810
长发绾君心
长发绾君心 2020-12-29 07:27

I have to write my own hash function. If I wanted to just make the simple hash function that maps each letter in the string to a numerical value (i.e. a=1, b=2, c=3, ...), i

10条回答
  •  失恋的感觉
    2020-12-29 08:13

    C++11 ships with a standard hashing function for strings.

    https://en.cppreference.com/w/cpp/string/basic_string/hash

    #include 
    #include // hash
    int main(){
        std::string s = "Hello";
        std::size_t hash = std::hash{}(s);
    }
    

提交回复
热议问题