Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

unicode

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

like image 391
esac Avatar asked Dec 07 '22 05:12

esac


2 Answers

use this :

wstring str1(L"Hello world");
TCHAR * v1 = (wchar_t *)str1.c_str();
like image 182
SaeidMo7 Avatar answered Dec 15 '22 01:12

SaeidMo7


#include <atlconv.h>

TCHAR *dst = W2T(src.c_str());

Will do the right thing in ANSI or Unicode builds.

like image 45
Ferruccio Avatar answered Dec 15 '22 01:12

Ferruccio