2012-02-12 13:32:38|?次阅读|上传:wustguangh【已有?条评论】发表评论
关键词:C/C++, 字符处理|来源:唯设编程网
3.char* 转换成数值类型:
3.1、char*转换成整数
int atoi(
const char *str
);
int _wtoi(
const wchar_t *str
);
int _atoi_l(
const char *str,
_locale_t locale
);
int _wtoi_l(
const wchar_t *str,
_locale_t locale
);
3.2、char*转换成长整形
long atol(
const char *str
);
long _atol_l(
const char *str,
_locale_t locale
);
long _wtol(
const wchar_t *str
);
long _wtol_l(
const wchar_t *str,
_locale_t locale
);
3.3、char*转换成64位的整形
__int64 _atoi64(
const char *str
);
__int64 _wtoi64(
const wchar_t *str
);
__int64 _atoi64_l(
const char *str,
_locale_t locale
);
__int64 _wtoi64_l(
const wchar_t *str,
_locale_t locale
);
3.4、char*转换成度浮点型
double atof(
const char *str
);
double _wtof(
const wchar_t *str
);
3.5、需包含的头文件总结:
| 函数名称 | 头文件 |
| _atoi64, _atoi64_l | <stdlib.h> |
| _wtoi64, _wtoi64_l | <stdlib.h> or <wchar.h> |
| atol | <stdlib.h> |
| _atol_l, _wtol, _wtol_l | <stdlib.h> and <wchar.h> |
| atoi | <stdlib.h> |
| _atoi_l, _wtoi, _wtoi_l | <stdlib.h> or <wchar.h> |
| atof | <math.h> and <stdlib.h> |
| _atof_l | <math.h> and <stdlib.h> |
| _wtof, _wtof_l | <stdlib.h> or <wchar.h> |
//1.取得CString的char*
CString::GetBuffer(0);
//2.CString to Int
int intv=atoi(CString::GetBuffer(0));
//3.CString to float
float floatv=(float)atof(CString::GetBuffer(0));
//4.CString to Long
long longvv=atol(CString::GetBuffer(0));
//5.CString to Double
double doublev=atof(CString::GetBuffer(0));
//6.各类型到CString
CString::Format(_T("%d,%f,%ld,%lf,%c,%s")
,int
,float
,long
,double
,char
,char*);
1.string类型:
有三个函数可以将字符串的内容转换为字符数组和C—string
data():返回没有”