2014-01-29 35 views
2

我試圖把這段代碼轉換成Unicode什麼是性病:: strtoul做的unicode

int fromHex(const supportlib::string_t &s) 
{ 
    return std::strtoul(s.c_str(), NULL, 16); 
} 

supportlib::string_t是通過typedef到std::stringstd::wstring取決於我是否要使用Unicode或ASCII編譯。

與大多數其他類型我可以找到一個寬版本,但不爲std::strtoul所以我應該用什麼來代替?與其他大多數類型一樣,std::wstrtoul並沒有這樣做。

我使用MingW和gcc 4.8.1。

當我在Unicode模式下編譯它,我得到這個錯誤:

error: cannot convert 'const wchar_t*' to 'const char*' for argument '1' to 'long unsigned int strtoul(const char*, char**, int)' 
+1

怎麼樣'STD: :stoul'?你可以根據你是否傳遞一個寬字符串來選擇正確的版本來獲得額外的獎勵,所以不需要自己動手。 – chris

+0

我也嘗試過,但我得到的錯誤是stoul不在std中。 – Devolus

+0

@chris,那我該如何使用它? – Devolus

回答

2

在C99至少,它在wchar.h和原型是這樣的:

unsigned long int wcstoul (const wchar_t * restrict nptr, wchar_t ** restrict endptr, int base);