UNICODE下CString 和 const char* 的相互转化
2016-03-08 10:51
381 查看
const char* 转换为 CString:
const char* c;
c = "abcdef";
CString s;
int len = strlen(c);
TCHAR* c1 = (TCHAR*)malloc(sizeof(TCHAR)*len);
MultiByteToWideChar( CP_ACP , 0 , c , len+1 , c1 , len+1);
s.Format(L"%s",c1);
CString 转换为 const char*:
CString str(L"This is a test");
int len = WideCharToMultiByte( CP_ACP , 0 , str , str.GetLength() , NULL , 0 , NULL , NULL );
char* pAscii =new char[len+1];
len = WideCharToMultiByte( CP_ACP , 0 , str , str.GetLength() , pAscii , len +1 , NULL ,NULL );
pAscii[len] = 0;
const char* xxx = (const char*)pAscii;
原文地址:http://www.cnblogs.com/aoyihuashao/archive/2010/04/09/1708439.html
const char* c;
c = "abcdef";
CString s;
int len = strlen(c);
TCHAR* c1 = (TCHAR*)malloc(sizeof(TCHAR)*len);
MultiByteToWideChar( CP_ACP , 0 , c , len+1 , c1 , len+1);
s.Format(L"%s",c1);
CString 转换为 const char*:
CString str(L"This is a test");
int len = WideCharToMultiByte( CP_ACP , 0 , str , str.GetLength() , NULL , 0 , NULL , NULL );
char* pAscii =new char[len+1];
len = WideCharToMultiByte( CP_ACP , 0 , str , str.GetLength() , pAscii , len +1 , NULL ,NULL );
pAscii[len] = 0;
const char* xxx = (const char*)pAscii;
原文地址:http://www.cnblogs.com/aoyihuashao/archive/2010/04/09/1708439.html
相关文章推荐
- 内网传输之共享文件
- Qt使用教程之使用Qt Quick UI表单(五)
- preg_match()检查错误,并抛出异常的各种应用场景
- MFC--控件改变编辑框的字体和颜色
- 【经典算法】——KMP,深入讲解next数组的求解
- Android推送技术研究
- Android布局案例之人人android九宫格
- 请慎用java的File#renameTo(File)方法
- 远程应用xp打印机之坑
- TCP连接建立断开
- 快速排序
- SQL Server 触发器
- 加油,启程!
- 什么时候使用异常
- Integer与int的种种比较你知道多少?
- 206. Reverse Linked List
- Ubuntu install Redis
- 杨辉三角的变形
- 堆排序
- Perl正则表达式总结_1