Convert CString to std::wstring

subbu picture subbu · Jan 11, 2010 · Viewed 32.9k times · Source

How can I convert from CString to std::wstring?

Answer

DanDan picture DanDan · Jan 11, 2010

To convert CString to std::wstring:

CString hi("Hi");
std::wstring hi2(hi);

And to go the other way, use c_str():

std::wstring hi(L"Hi");
CString hi2(hi.c_str());