gpt4 book ai didi

c++ - 将十六进制值存储在字符串 C++ 中

转载 作者:太空宇宙 更新时间:2023-11-04 16:09:19 25 4
gpt4 key购买 nike

例如:

char str[] = {0x1B, 0x54, 0x32, 0xFE, 0x88, 0x10, 0x34, 0x6F, 0x54};

但这是C风格。那么我如何在不使用 C 函数的情况下对 std::string 做同样的事情呢?

最佳答案

So how can i do same with std::string and without using C functions?

试试这个:

std::string str{0x1B, 0x54, 0x32, 0xFE, 0x88, 0x10, 0x34, 0x6F, 0x54};

或者这个:

using namespace std::literals::string_literals;

auto str = "\x1B5432FE8810346F54"s;

或者这个:

std::string str = "\x1B5432FE8810346F54";

关于c++ - 将十六进制值存储在字符串 C++ 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30423469/

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