将字符串转换为int类型
CString str(_T("381"));
int data = _wtoi(str);
将字符串转换为双精度
注:Unicode下可使用_wtof。不过最好使用_tstof,它实际上是宏,在不同的字符集下解释不同。这样两种字符集都可以编译通过。
CString str(_T("381.33"));
double Text = _tstof(str);
MSDN中关于数据转换的资料:
Data-Conversion Routines
Routine |
Use |
atof, _atof_l, _wtof, _wtof_l |
Convert string to float |
atoi, _atoi_l, _wtoi, _wtoi_l |
Convert string to int |