WCHAR char CString等常用类型互转

1、CString to WCHAR*:

WCHAR *wch = (WCHAR*)str.GetBuffer(str.GetLength());

str为CString类型。


2、WCHRA* to char*:

memset(buf, 0, bufInLen);
	// WCHRA to char
	WideCharToMultiByte( CP_ACP, 0, wch, -1, buf, bufInLen, NULL, NULL );
其中的buf为char类型字符串,bufInLen为buf字符串的长度,wch是最上面的那个WCHAR字符串。

上面两个转换一起使用,可以把中英文的CString字符串转换成ascii编码。


3、char* to WCHAR*:

// char to WCHAR
	WCHAR* wch = new WCHAR(bufLen);
	memset(wch, 0, sizeof(wch));
	MultiByteToWideChar( CP_ACP, 0, buf, bufLen, wch, bufLen/sizeof(WCHAR) );
其中的buf为char类型字符串,bufInLen为buf字符串的长度。

4、WCHAR* to CString:

// WCHAR to CString
	for(unsigned int i=0; i<wcslen(wch); i++)
		str.AppendChar(wch[i]);
上面的str为CString类型。wch为3那里的WCHAR字符串。
3、4组合起来可以把ascii的字符串转换成中英文的CString。


5、int to char*

		char t_id[4] = "";
		char *p = itoa(i, t_id, 10);
这里i为int类型数据,使用itoa可以将int类型转换成char*类型数据。itoa在stdlib.h头文件里。


6、char*toint

char str = "123";
int n = atoi(str);
将字符串str转换成整数n.






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值