类型转换-尝试将c#转换为c++

type conversion - trying to convert c# to c++

本文关键字:转换 c++ 类型转换      更新时间:2023-10-16
byte[] len = BitConverter.GetBytes((ulong)text.Length);
Array.Reverse(len);
list.AddRange(len);

不知道如何将这个代码段转换为C++,有什么帮助吗?

//this is your list
std::list<char> list;
std::string     text;
//populate with whatever
constexpr count=sizeof(std::string::size_type);
std::array<char, count> len;
auto size=text.size();
std::memcpy(len.data(), &size, count);
list.insert(list.end(), len.rbegin(), lend.rend());

编辑:以错误的方式获取内存集的参数。现已修复。