gpt4 book ai didi

c++ - 以十六进制或十进制打印到 stdout,一个 std::string 作为字节序列

转载 作者:行者123 更新时间:2023-11-30 00:35:28 25 4
gpt4 key购买 nike

<分区>

我正在使用的 API 返回一个字节序列作为 std::string。

如何将其打印到标准输出,格式化为十六进制或十进制的序列。

这是我使用的代码:

        int8_t i8Array[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
std::string i8InList(reinterpret_cast<const char*>(i8Array), 16);
std::string i8ReturnList;

client.GetBytes(i8ReturnList, i8InList);

cout << "GetBytes returned ";
std::copy(i8ReturnList.begin(), i8ReturnList.end(), std::ostream_iterator<int8_t>(std::cout << " " ));

我希望收到相同的输入,但顺序相反。然而这段代码打印的是:

GetBytes returned   ☺☻♥♦♣
♫☼

注意:字节序列是任意字节序列,它不是书面语言的表示。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com