如何获取c ++中的字符串的哈希码 [英] how to get hash code of a string in c++
本文介绍了如何获取c ++中的字符串的哈希码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下java代码返回字符串的哈希码。
Following java code returns hash code of a string.
String uri = "Some URI"
public int hashCode() {
return uri.hashCode();
}
我想将此代码翻译为c ++。在c ++中有一个函数availabe或一个简单的方法来翻译这个。
I want to translate this code to c++. Is there any function availabe in c++ or an easy way to translate this.
推荐答案
Boost提供了散列函数:
Boost provides a hash function:
#include <boost/functional/hash.hpp>
int hashCode()
{
boost::hash<std::string> string_hash;
return string_hash("Hash me");
}
这篇关于如何获取c ++中的字符串的哈希码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文