kimezehig
kimezehig

Reputation: 21

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?

Upvotes: 1

Views: 19328

Answers (2)

Galik
Galik

Reputation: 48605

You can do this:

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

Upvotes: 2

utnapistim
utnapistim

Reputation: 27365

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

Upvotes: 9

Related Questions