How does “\x” work in a String?

后端 未结 4 588
一生所求
一生所求 2021-01-02 14:06

I\'m writing a C/C++ program that involves putting a hex representation of a number into a string and I\'m confused as to how \\x works. I\'ve seen examples wh

4条回答
  •  有刺的猬
    2021-01-02 15:12

    The translation is done at compile-time so that every string you manually enter into the source code with \x and such ends up being the character it represents in the binary. If you want to do this at run-time you will need to invoke a parse function like strtol() using base 16 passing the string containing the hex and cast it to a char.

提交回复
热议问题