CString 和 const char* 的相互转化(UNICODE)。
2010-04-09 16:30
435 查看
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);
--------------
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 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; char a = xxx[0]; char b = xxx[1]; char c = xxx[2]; char d = xxx[3];
相关文章推荐
- UNICODE下CString 和 const char* 的相互转化
- UNICODE下宽字符的CString转换为const char *和char到WCHAR的相互转换
- UNICODE下宽字符的CString转换为const char *和char到WCHAR的相互转换
- MFC中,Unicode和多字节字符集下 CString和char的转化
- CString 转化为 const char*的方法(经验证) “0x77d287f1”指令引用的“0x00000000”内存。该内存不能为“written”。
- 使用Unicode下的cannot convert parameter 1 from 'CString' to 'const char *' 解决办法
- Unicode与UTF8相互转化(使用MultiByteToWideChar)
- NSString,NSData,std::string,const char*相互转化
- CString 与 char * 和 const char*的转换,以及在Unicode项目中的使用.
- String,CString,TCHAR,char间区别和联系以及相互转化
- UNICODE下宽字符的CString转换为const char *
- CString 强制转化为const char*,作为形参带入函数内出错。用CW2A解决
- MFC中,Unicode与多字符集下CString与char或char*等的转化
- 类型转换 -- 使用Unicode下的cannot convert parameter 1 from 'CString' to 'const char *' 解决办法
- CString与std::string unicode下相互转化
- UNICODE下宽字符的CString转换为const char *
- Unicode编码的项目中CString、char* 、wstring、string的相互转换
- MFC:Unicode和多字节字符集下 CString和char的转化(MFC中)
- MFC中Unicode与多字节编码中遇到的CString与char或char*的转化问题
- VC++中,CString,in,char,等数据类型的相互转化