Convert CString to std::wstring

给你一囗甜甜゛ 提交于 2019-12-18 18:55:35

问题


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;



回答4:


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


来源:https://stackoverflow.com/questions/2041241/convert-cstring-to-stdwstring

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!