C++ Transform string into its ASCII representation

Viewed 87

I'm writing a simple packet parser. For testing, I've prepared data in format as followed:

std::string input = "0903000000330001 ... ";

and I need to transform it into something like this

0x09 0x03 0x00 0x00 ...

Could you help me how I should construct the new string?

I already tried these ...

std::string newInput = "\x09\x03\x00 ... ";
std::string newInput = "\u0009\u0003\u0000 ...";

but the program returns that the size of this string is only two.

std::cout << newInput.size() << std::endl;
 > 2

I'm really missing or misunderstanding something...

2 Answers
Related