我正在尝试将此代码转换为 Unicode
int fromHex(const supportlib::string_t &s)
{
return std::strtoul(s.c_str(), NULL, 16);
}
supportlib::string_t
会根据我是否想编译为Unicode或ASCII而被定义为std :: string 或std :: wstring 。
对于大多数其他类型,我可以找到宽字符版本,但对于std :: strtoul ,我找不到,那么我应该使用什么呢?std :: wstrtoul 并不能像大多数其他类型一样解决问题。
我正在使用带有gcc 4.8.1的MingW。
当我以Unicode模式编译它时,我会得到这个错误:
error: cannot convert 'const wchar_t*' to 'const char*' for argument '1' to 'long unsigned int strtoul(const char*, char**, int)'
std::stoul
怎么样?你还会得到一个额外的奖励,它会根据你传递的是宽字符串还是普通字符串来选择正确的版本,所以不需要自己处理。 - chris