首页 > 代码库 > Cstring与char*、String转Cstring(unicode编码)

Cstring与char*、String转Cstring(unicode编码)

unicode编码下,cstring与char*、String转Cstring的转换方法:

 1 . CSstring转char *
 wchar_t *psw_wchar = psw.GetBuffer(); //获取psw的宽字符用数组保存
 psw.ReleaseBuffer();

 

 int nLen = psw.GetLength();//获取psw的字符数
 char *encrypt = new char[nLen * 2 + 1];
 memset(encrypt, 0, nLen * 2 + 1);
 int rtnVal = (int)wcstombs(encrypt, psw_wchar, nLen * 2 + 1); //宽字符转换为多字节字符 


2 . String转Cstring
 psw = szDigest.c_str();

                                                                                                                                                                                                                                     SYQ

Cstring与char*、String转Cstring(unicode编码)