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 );
上面两个转换一起使用,可以把中英文的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) );
4、WCHAR* to CString:
- // WCHAR to CString
- for(unsigned int i=0; i<wcslen(wch); i++)
- str.AppendChar(wch[i]);
3、4组合起来可以把ascii的字符串转换成中英文的CString。
5、int to char*
- char t_id[4] = "";
- char *p = itoa(i, t_id, 10);
6、char* to int
- char str = "123";
- int n = atoi(str);