subbu
subbu

Reputation: 3299

Convert CString to std::wstring

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

Upvotes: 17

Views: 41447

Answers (4)

Danil
Danil

Reputation: 895

CString s = _T("Привет");
USES_CONVERSION;
std::wstring ws(A2W((LPCTSTR)s));

Upvotes: 0

DanDan
DanDan

Reputation: 10562

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());

Upvotes: 28

Naveen
Naveen

Reputation: 73493

This should work as CString has operator LPCTSTR() defined:

CString s;
std::wstring s1 = s;

Upvotes: 2

Ashish
Ashish

Reputation: 8529

Try this:

std::wstring strString((LPCTSTR)strCString);

Upvotes: 1

Related Questions