[英]Load boost::uuid from bytes in c++
I use .data()
to get 16 bytes data array. 我使用
.data()
来获取16字节的数据数组。
Later I write it to a file and I want to load it back to a uuid
variable. 后来我将它写入文件,我想将其加载回一个
uuid
变量。 Should I just perform memory copy to the variable as : (c++11) 我应该只对变量执行内存复制:(c ++ 11)
boost::uuids::uuid uuid = boost::uuids::random_generator()();
char[16] data;
std::copy_n(&uuid, 16, data); // copy to data
std::copy_n(data, 16, &uuid); // copy from data (?)
First, whenever you find yourself wondering how to use Boost classes, there's the docs: 首先,每当你发现自己想知道如何使用Boost类时,就会有以下文档:
http://www.boost.org/doc/libs/1_58_0/libs/uuid/uuid.html http://www.boost.org/doc/libs/1_58_0/libs/uuid/uuid.html
{ // example using memcpy
unsigned char uuid_data[16];
// fill uuid_data
boost::uuids::uuid u;
memcpy(&u, uuid_data, 16);
}
{ // example using aggregate initializers
boost::uuids::uuid u =
{ 0x12 ,0x34, 0x56, 0x78
, 0x90, 0xab
, 0xcd, 0xef
, 0x12, 0x34
, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef
};
}
Since memcpy
works I expect copy_n
will work also. 由于
memcpy
工作,我希望copy_n
也可以工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.