常用类型转换

 一、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-结果

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值