How can I convert 'wchar_t
*' to 'const char *
' ?
如何将“wchar_t *”转换为“const char *”?
using C++ MFC VS2010.
使用c++ MFC VS2010。
Thank you.
谢谢你!
2 个解决方案
#2
6
As the question is about MFC, I would suggest the following:
由于问题是关于MFC,我建议如下:
CStringA a = "Test";
CStringW w = L"Test";
a = CStringA(w);
w = CStringW(a);
I typically need the following conversions:
我通常需要以下转换:
CString t = _T("Test"); // depends on TCHAR type
a = CStringA(t); // does not depend on TCHAR type
w = CStringW(t);
CStringW and CStringA have operators LPCWSTR and LPCSTR respectivelly.
CStringW和CStringA分别有LPCWSTR和LPCSTR操作符。
#1
#2
6
As the question is about MFC, I would suggest the following:
由于问题是关于MFC,我建议如下:
CStringA a = "Test";
CStringW w = L"Test";
a = CStringA(w);
w = CStringW(a);
I typically need the following conversions:
我通常需要以下转换:
CString t = _T("Test"); // depends on TCHAR type
a = CStringA(t); // does not depend on TCHAR type
w = CStringW(t);
CStringW and CStringA have operators LPCWSTR and LPCSTR respectivelly.
CStringW和CStringA分别有LPCWSTR和LPCSTR操作符。