正确的UNICODE在做这件事的方式兼容MFC如下:
CString sInt = _T("10");
int n = _ttoi(sInt);
CString sFloat = _T("10.1");
float f = _ttof(sFloat);
Run Code Online (Sandbox Code Playgroud)
正如David Heffernan所提到的:如果你的项目配置只是UNICODE并且你没有使用MBCS并且没有任何计划针对像Windows 98这样的旧MS操作系统,你可以使用:
CStringW s = L"10";
int i = _wtoi(s);
Run Code Online (Sandbox Code Playgroud)
在C++ 11中,您可以使用以下内容:
std::string sInt = "10";
int i = std::stoi(sInt);
std::string sFloat = "10.1";
double d = std::stod(sFloat);
Run Code Online (Sandbox Code Playgroud)