一、
使用函数_tcscpy_s:
CString theString( "This is a test" );
int sizeOfString = (theString.GetLength() + 1);
LPTSTR lpsz = new TCHAR[ sizeOfString ];
_tcscpy_s(lpsz, sizeOfString, theString);
最后再转换一下lpsz为const型的
LPTSTR在UNICODE环境下编译是wchar_t类型
二、
CString str = _T("Hello World!");
char szStr[256] = {0};
wcstombs(szStr, str, str.GetLength());
const char * p = szStr;
本文介绍了如何将MFC中的CString对象转换为字符数组的过程。包括使用_tcscpy_s进行安全字符串复制,以及通过wcstombs函数实现宽字符到多字节字符的转换。这些方法对于在不同编码环境下操作字符串非常有用。
5074

被折叠的 条评论
为什么被折叠?



