◐ Shell
clean mode source ↗

std::hash (std::string, std::wstring, std::u16string, std::u32string)

Da cppreference.com.

Questa pagina è stata tradotta in modo automatico dalla versione in ineglese della wiki usando Google Translate.

La traduzione potrebbe contenere errori e termini strani. Muovi il puntatore sopra al testo per vedere la versione originale. Puoi aiutarci a correggere gli gli errori. Per ulteriori istruzioni clicca qui.

Click here for the English version of this page

<metanoindex/>

<tbody> </tbody>

Elemento definito nell'header

<string>

template<> struct hash<std::string>; template<> struct hash<std::wstring>; template<> struct hash<std::u16string>; template<> struct hash<std::u32string>;

(dal C++11)

The template specializations of std::hash for the various string classes allow users to obtain hashes of strings.

Esempio

The following code shows one possible output of a hash function used on a string:

#include <iostream>
#include <string>
#include <functional>
 
int main()
{
    std::string s = "Stand back! I've got jimmies!";
    std::hash<std::string> hash_fn;

    size_t hash = hash_fn(s);

    std::cout << hash << '\n';
}

Output:

Vedi anche