1. 程式人生 > >Unicode字符集下,CString 轉換為char型別

Unicode字符集下,CString 轉換為char型別

//CString 轉換為char型別,Unicode字符集下

    UINT num = WideCharToMultiByte(CP_ACP,0,m_SendData,m_SendData.GetLength(),NULL,0,NULL,NULL); 
                                                //為多位元組字元陣列申請空間,陣列大小為按位元組計算的寬位元組位元組大小
    char * c = new char[num];                   //以位元組為單位
    WideCharToMultiByte(CP_ACP,0
,m_SendData,m_SendData.GetLength(),c,num,NULL,NULL);//寬位元組編碼轉換成多位元組編碼

其中,m_SendData為待轉換的CString型別,c為轉換後的字串,num為字串長度。