c++c-stringsconverterswchar

Use wtoi with radix in c++


I need to convert a hex value stored in a wchar_t c-style string to an int. the atoi function has the parameter radix for this, but the wtoi only takes a wchar_t. Is there a function(usable for c++, much c functions are deprecated in c++) or another way to achieve this?;


Solution

  • std::stoi is overloaded on both std::string and std::wstring and takes an optional base parameter. You can construct a std::wstring form a wchar_t c-style string.