我正在一个经理课程中工作,该课程包含表示路径的字符串。从这个字符串,我想使用这样的代码进行boost.uuid:

m_log->addMessage("Generating UUID from path",ZEL_APPENDER,LOGLEVEL_DEBUG);
boost::uuids::string_generator str_gen;
boost::uuids::uuid generatedUUID = str_gen(full_path);

assert(generatedUUID.is_nil() == false);
char msg[500];
snprintf(msg,500,"Successfully generated UUID %s from path",boost::uuids::to_string(generatedUUID).c_str());
m_log->addMessage(msg,ZEL_APPENDER,LOGLEVEL_DEBUG);

但是不幸的是,我发现即使Full_Path有所不同,生成的字符串总是相同的。

另外,当我尝试一个像这样的超简单示例时:

 string s1("helloworld");
 boost::uuids::string_generator str_gen;
 boost::uuids::uuid generatedUUID = str_gen(s1);
 cout << "s1: " << boost::uuids::to_string(generatedUUID) << endl;

Boost引发了一个运行时异常,说字符串无效。你可以帮帮我吗?我发现的唯一文档来源是 这里

提前致谢。

有帮助吗?

解决方案

基于 标题中的代码 代码不会生成 哈希 但是解析 uuid-as string 并将其转换为UUID。

听起来您正在根据路径寻找哈希,这与UUID不同。 UUID是唯一的,这意味着一个人可能具有在不同UUID下的关联容器中存储相同值的路径。

您可能会更好地看待 boost.hash.

其他提示

我想你应该读 http://www.boost.org/doc/libs/1_59_0/libs/uuid/uuid.html#boost/uuid/string_generator.hpp 小心。你用 String Generator,但在文章中 boost::uuids::string_generator 班级生成a uuid 从字符串。如果您想使用 boost::uuids::string_generator,您必须在您的 gen().

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top