Jon*_*nek 6 c++ mfc internationalization visual-c++
我正在开展国际化项目.其他语言(如阿拉伯语或中文)是否对0-9以外的数字使用不同的表示形式?如果是这样,atoi()的版本是否会考虑这些其他表示?
我应该补充一点,我主要关心解析用户的输入.如果用户键入其他一些表示,我想确保将其识别为数字并相应地对待它.
我可以使用std::wistringstream和locale生成这个整数.
#include <sstream>
#include <locale>
using namespace std;
int main()
{
locale mylocale("en-EN"); // Construct locale object with the user's default preferences
wistringstream wss(L"1"); // your number string
wss.imbue( mylocale ); // Imbue that locale
int target_int = 0;
wss >> target_int;
return 0;
}
Run Code Online (Sandbox Code Playgroud)