VC中数字与字符串转换方法
u 字符串转数字
l 1.CRT函数
| ASCII | UNICODE | TCHAR | VS2005 |
int | atoi | _wtoi | _tstoi,_ttoi | _atoi_l,_wtoi_l |
long | atol | _wtol | _tstoi,_ttoi | _atoi_l,_wtoi_l |
__int64 | _atoi64 | _wtoi64 | _tstoi64,_ttoi64 | _atoi64_l,_wtoi64_l |
float |
|
|
| _atoflt,_atoflt_l |
double | atof | _wtof | _tstof,_ttof | _atof_l,_wtof_l,_atodbl,_atodbl_l |
long double |
|
|
| _atoldbl,_atoldbl_l |
l 2.使用sscanf
l 3.Windows SDK:<shlwapi.h>:StrToInt
l 4.MFC/ATL:CString::Format
u 数字转字符串
l 1.CRT函数
| ASCII | UNICODE | TCHAR | VS2005 |
int | Itoa,_itoa | _itow | _itot |
|
long | Ltoa,_ltoa | _ltow | _ltot |
|
__int64 | _i64toa | _i64tow | _i64tot |
|
double | Gcvt,_gcvt,_ecvt,_fcvt | _wtof | _tstof,ttof | _gcvt_s,_ecvt_s,_fcvt_s |
l 2.使用sprintf
l 3.<strsafe.h>:StringCbPrintf
u 通用相互转换方法
l C++流方式:stringstream
l 2.boost库:boost:: lexical_cast
摘自MSDN:Data-Conversion Routines
Routine | Use |
Convert string to float | |
Convert string to int | |
Convert string to __int64 | |
Convert string to long | |
Convert double to string of specified length | |
Convert double to string with specified number of digits following decimal point | |
Convert double number to string; store string in buffer | |
Convert int to string | |
_i64toa, _ui64toa, _i64tow, _ui64tow, _i64toa_s, _ui64toa_s, _ui64tow_s | Convert __int64 to string |
Convert long to string | |
Convert string to double | |
Convert string to long integer | |
Convert string to unsigned long integer | |
Convert unsigned long to string | |
Convert wide-character string to a double | |
Convert wide-character string to int | |
Convert wide-character string to __int64 | |
Convert wide-character string to long |
原帖:http://www.cppblog.com/tbyxyz/articles/str2num.html