C++ Hash function for string in unordered_map

前端 未结 5 1593
被撕碎了的回忆
被撕碎了的回忆 2021-02-05 00:46

It seems as if C++ does not have a hash function for strings in the standard library. Is this true?

What is a working example of using a string as a key in an unordered_

5条回答
  •  终归单人心
    2021-02-05 01:07

    I ran into this today (actually with wstring, not string, but it's the same deal): using wstring as a key in an unordered_map generates an error about no hash function being available for that type.

    The solution for me was to add:

    #include 
    

    Believe it or not, without the #include directive I still had the wstring type available but apparently NOT the ancillary functions like the hash. Simply adding the include above fixed it.

提交回复
热议问题