简体   繁体   English

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

[英]Store hex value in string C++

For example : 例如 :

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

But this is C style. 但这是C风格。 So how can i do same with std::string and without using C functions? 那么如何在不使用C函数的情况下使用std::string做同样的事情?

So how can i do same with std::string and without using C functions? 那么如何在不使用C函数的情况下使用std :: string做同样的事情?

try this: 尝试这个:

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

or this: 或这个:

using namespace std::literals::string_literals;

auto str = "\x1B5432FE8810346F54"s;

or this: 或这个:

std::string str = "\x1B5432FE8810346F54";

你可以这样做:

std::string s = "\x1B\x54\x32\xFE\x88\x10\x34\x6F\x54";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM