简体   繁体   中英

Store hex value in string C++

For example :

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

But this is C style. So how can i do same with std::string and without using C functions?

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

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";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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