一、to string
1)int to char temp[200]
itoa(i,temp,10);//将i转换为字符串放入temp中,最后一个数字表示十进制
itoa(i,temp,2); //按二进制方式转换
2)long to char temp[200]
ltoa(l,temp,10);
二、DWORD to string
DWORD c=8590500;
char b[32] = _T("");
itoa(c,b,10);
string d=string(b);
三、字符串转换为其它数据类型
1)String to char temp[200]
strcpy(temp,"123");
strcpy(temp,a.c_str());
2)char temp[200] to int
i = atoi(temp);
3)char temp[200] to long
l = atol(temp);
4)char temp[200] to double
d = atof(temp);
四、其它数据类型转换到CString
CString str;
1)整数(int) str.Format("%d",i);
2)浮点数(float) str.Format("%f",i);
五、string to int
1) string c="200";
int b=atoi(c.c_str());
六、数据类型转化 string to LPSTR
CString temp;
LPSTR cmdLine;
std::string processname=ProcessName();
temp.Format("%s",processname.c_str());
cmdLine=temp.GetBuffer(0);
七、char temp[n] 转化为string
string c=string(temp);
八、string to CString
string b="ting";
CString a=b.c_str();
九、int to unsigned short
int intVal;
unsigned short usVal = static_cast<unsigned short>(intVal);
如果 intVal>=65536 usVal为: intVal的模65536
如果 intVal<0 usVal为: 先对intValu取绝对值,然后取模.结果为0 保留.其它则usValu为:65536-结果