C++: Converting Hexadecimal to Decimal

前端 未结 7 1745
一向
一向 2020-11-30 11:49

I\'m looking for a way to convert hex(hexadecimal) to dec(decimal) easily. I found an easy way to do this like :



        
7条回答
  •  抹茶落季
    2020-11-30 11:57

    I use this:

    template 
    bool fromHex(const std::string& hexValue, T& result)
    {
        std::stringstream ss;
        ss << std::hex << hexValue;
        ss >> result;
    
        return !ss.fail();
    }
    

提交回复
热议问题