一、CString转char *
CString pb=_T("abc"); int len = WideCharToMultiByte(CP_UTF8, 0, pb, pb.GetLength(), NULL, 0, NULL, NULL); char* pa = new char[len + 1]; len = WideCharToMultiByte(CP_UTF8, 0, pb, pb.GetLength(), pa, len + 1, NULL, NULL); pa[len] = 0; //pa就是最后转换成的char *
二、char * 转CString
CString st=_T("123"); int nLength = st.GetLength(); int nBytes = WideCharToMultiByte(CP_ACP,0,st,nLength,NULL,0,NULL,NULL); char* path1 = new char[ nBytes + 1]; memset(path1,0,nLength + 1); WideCharToMultiByte(CP_OEMCP, 0, st, nLength, path1, nBytes, NULL, NULL); path1[nBytes] = 0;
原文地址:https://www.cnblogs.com/tianxiafeiyu/p/9119615.html
时间: 2024-09-27 16:17:59