Search code examples
c++mfchexdata-conversionunsigned-long-long-int

How to convert a hex string to an unsigned long?


I have following hex value

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

How to convert this in to an unsigned long?


Solution

  • #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;
    }