C++ 如何:将boost::endian缓冲区类型转换回本机格式

C++ 如何:将boost::endian缓冲区类型转换回本机格式,c++,boost,C++,Boost,buffers.hpp的boost::endian示例演示了如何将本机格式转换为big或little-endian。如何执行反向函数以将大/小endian格式恢复为本机格式 例如: #include <stdint.h> #include <boost/endian/buffers.hpp> using namespace boost::endian; int main() { uint64_t v= uint64_t(0x1011121314151617); bi

buffers.hpp的boost::endian示例演示了如何将本机格式转换为big或little-endian。如何执行反向函数以将大/小endian格式恢复为本机格式

例如:

#include <stdint.h>
#include <boost/endian/buffers.hpp>

using namespace boost::endian;

int main() {
uint64_t v= uint64_t(0x1011121314151617);

big_uint64_buf_t    b;
little_uint64_buf_t l;

// Set values, implicit native_to_*
b= v;
l= v;

// Get values, does not work
v= b;
v= l;

return 0;
}
从little-endian格式转换回时也会发生类似错误。

使用:

v= b.value(); // and/or
v= l.value();
虽然示例中缺少值函数用法,但它记录在成员函数列表中

v= b.value(); // and/or
v= l.value();