如何将 'wchar_t *' 转换为 'const char *'

2022-01-12 00:00:00 c++ mfc

如何将 'wchar_t *' 转换为 'const char *' ?

How can I convert 'wchar_t *' to 'const char *' ?

使用 C++ MFC VS2010.

using C++ MFC VS2010.

谢谢.

推荐答案

由于问题是关于MFC的,我建议如下:

As the question is about MFC, I would suggest the following:

CStringA a = "Test";
CStringW w = L"Test";
a = CStringA(w);
w = CStringW(a);

我通常需要以下转换:

CString t = _T("Test"); // depends on TCHAR type
a = CStringA(t); // does not depend on TCHAR type
w = CStringW(t);

CStringW 和 CStringA 分别有运算符 LPCWSTR 和 LPCSTR.

CStringW and CStringA have operators LPCWSTR and LPCSTR respectivelly.

相关文章