MFC开发IM-字符串转换大全

xiaoxiao2021-02-28  26

1.CString 转 LPCTSTR 

  CString cs_temp;

  LPCTSTR lpcstr=cs_temp;

2.char数组 转 CString

char* abc = szResponse; CString temp(abc);

resJson = abc;

3.char * 转 CString

char* abc = szResponse;

CString temp(abc);

4.CString to char数组

    const char* temp  = CStringToConstChar(resJson); char recv[50000];

strncpy_s(recv,temp,50000);

CStringToConstChar函数的实现在最下面

//*****以下为********CStringToConstChar函数的实现

 const char* mainDlg::CStringToConstChar(CString str){

 const char* res; //CString str(L"This is a test");int len = WideCharToMultiByte( CP_UTF8 , 0 , str , str.GetLength() , NULL , 0 , NULL , NULL );char* pAscii =new char[len+1];len = WideCharToMultiByte(  CP_UTF8 , 0 , str , str.GetLength() , pAscii , len +1 , NULL ,NULL );

pAscii[len] = 0;

//const char* res = (const char*)pAscii; res = (const char*)pAscii; char a = res[0]; char b = res[1]; char c = res[2]; char d = res[3];  return res;    }

//******以上为*******CStringToConstChar函数的实现

转载请注明原文地址: https://www.6miu.com/read-2632930.html

最新回复(0)