C++基本类型哈希值学习

完全转自:https://blog.csdn.net/liyazhen2011/article/details/100181869

1.例子

#include <iostream>
#include <string>
using namespace std;
 
int main()
{
    cout << "hash value = " << hash<int>()(123) << endl;
    cout << "hash value = " << hash<long>()(123L) << endl;
    cout << "hash value = " << hash<string>()("April") << endl;
    cout << "hash value = " << hash<const char*>()("April") << endl;
    cout << "hash value = " << hash<char>()('A') << endl;
    cout << "hash value = " << hash<float>()(3.141592653) << endl;
    cout << "hash value = " << hash<double>()(3.141592653) << endl;
}

// 运行结果:
hash value = 123
hash value = 123
hash value = 3873163312835782020
hash value = 14878092512267864660
hash value = 65
hash value = 1078530011
hash value = 4614256656550717752

 

posted @ 2024-06-26 01:34  lypbendlf  阅读(3)  评论(0编辑  收藏  举报