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

esac picture esac · Dec 3, 2009 · Viewed 14.2k times · Source

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*?

Answer

SaeidMo7 picture SaeidMo7 · Jan 3, 2016

use this :

wstring str1(L"Hello world");
TCHAR * v1 = (wchar_t *)str1.c_str();