Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert 'wchar_t *' to 'const char *'

Tags:

c++

mfc

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

using C++ MFC VS2010.

Thank you.

like image 738
cnd Avatar asked Oct 20 '11 11:10

cnd


1 Answers

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

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.

like image 105
Vyacheslav Lanovets Avatar answered Oct 11 '22 12:10

Vyacheslav Lanovets