如何将十六进制字符串转换为无符号长整型字符串



我有以下十六进制值

CString str;
str = T("FFF000");

如何将其转换为unsigned long

您可以使用

strtol适用于常规 C 字符串的函数。它使用指定的基数将字符串转换为长整型:

long l = strtol(str, NULL, 16);

细节和好例子:http://www.cplusplus.com/reference/clibrary/cstdlib/strtol/

#include <sstream>
#include <iostream>
int main()
{
    std::string s("0xFFF000");
    unsigned long value;
    std::istringstream iss(s);
    iss >> std::hex >> value;
    std::cout << value << std::endl;
    return 0;
}

最新更新