在Unicode字符集下,使用_ttoi()和_ttof()函数:
例:CString str = _T(“23”);
float f_value = _ttof(str);
int i_value = _ttoi(str);
在非Unicode字符集下,使用atoi()和atof()函数:
例:CString str = _T(“23”);
float f_value = atof(str);
int i_value = atoi(str);
注:输入str的范围不要超出int或float类型的范围。
每次用到转换时都要查找,借此机会做个总结,方便自己使用,也方便与大家交流。
本文介绍了在不同字符集环境下,如何使用特定函数将字符串转换为整数或浮点数。在Unicode环境中,推荐使用_ttoi()和_ttof();而在非Unicode环境下,则使用atoi()和atof()。注意,转换的字符串不应超出类型范围。
7536

被折叠的 条评论
为什么被折叠?



