---
title: "WCHAR char CString等常用类型互转"
author: "mmdev"
date: "2011-12-14T15:35:00Z"
tags: []
slug: "wchar-char-cstring"
draft: false
lastmod: "2012-05-28T09:40:41Z"
id: 1542492
url: "https://mmdev.iteye.com/blog/1542492"
---

**1、CString to WCHAR\*:**

str为CString类型。

**2、WCHRA* to char\*:**

其中的buf为char类型字符串，bufInLen为buf字符串的长度，wch是最上面的那个WCHAR字符串。

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

**3、char* to WCHAR\*:**

其中的buf为char类型字符串，bufInLen为buf字符串的长度。

**4、WCHAR* to CString:**

上面的str为CString类型。wch为3那里的WCHAR字符串。  
3、4组合起来可以把ascii的字符串转换成中英文的CString。

**5、int to char\***

这里i为int类型数据，使用itoa可以将int类型转换成char\*类型数据。itoa在stdlib.h头文件里。

**6、char\*toint**

将字符串*str*转换成整数n.