Convert CString to std::wstring

2019-02-12 03:41发布

问题:

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

回答1:

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


回答2:

Try this:

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


回答3:

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

CString s;
std::wstring s1 = s;