I am trying to parse the input string from a user which can be "\x3B\xDE\x7C"
std::cout << std::string("\x3B\xDE\x7C") << std::endl;
results in
;Ì|
How do I parse it to result in:
"\x3B\xDE\x7C"
, preferably "3B DE 7C"
?
The \x
is not stored in the string actually, it got detected as an escape sequence. Any escape sequence does not store the characters you see on the screen, it stores the actual character specified.
Further, it converts to the Hex. For example, if you put:
std::cout << std::string("\x3B");
The string will store ;
character, no longer that 3B
. Since you've put a std::endl
, that results those weird characters after that semicolon.
Notice that you may use other keys except escape sequences in strings.