Search code examples
c++unicodetchar

How to convert std::wstring to a TCHAR*?


How to convert a std::wstring to a TCHAR*? std::wstring.c_str() does not work since it returns a wchar_t*.

How do I get from wchar_t* to TCHAR*, or from std::wstring to TCHAR*?


Solution

  • #include <atlconv.h>
    
    TCHAR *dst = W2T(src.c_str());
    

    Will do the right thing in ANSI or Unicode builds.