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

后端 未结 1 935
感情败类
感情败类 2020-12-19 05:36

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

using C++ MFC VS2010.

Thank you.

相关标签:
1条回答
  • 2020-12-19 06:15

    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.

    0 讨论(0)
提交回复
热议问题