Convert hexadecimal string with leading “0x” to signed short in C++?

前端 未结 6 805
孤城傲影
孤城傲影 2020-12-04 00:37

I found the code to convert a hexadecimal string into a signed int using strtol, but I can\'t find something for a short int (2 bytes). Here\' my p

6条回答
  •  有刺的猬
    2020-12-04 01:00

    If you know the data is always going to be in that format, couldn't you just do something like:

    myInt << std::hex << currentString.c_str() +2; // skip the leading "0x"
    

提交回复
热议问题