【问题标题】:trying to convert c# to c++试图将 c# 转换为 c++
【发布时间】:2013-02-19 19:37:44
【问题描述】:
byte[] len = BitConverter.GetBytes((ulong)text.Length);
Array.Reverse(len);
list.AddRange(len);

不知道如何将此 sn-p 转换为 C++,有什么帮助吗?

【问题讨论】:

  • 我不完全确定该代码应该做什么/
  • 字符长度[4]; len[3] = (int)((tmplong >> 24) & 0xFF); len[2] = (int)((tmplong >> 16) & 0xFF); len[1] = (int)((tmplong >> 8) & 0xFF); len[0] = (int)((tmplong & 0xFF)); strcat(tmp, len);

标签: c++ type-conversion


【解决方案1】:
//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());

编辑:为 memset 获取错误的参数。现已修复。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-16
    相关资源
    最近更新 更多