How can I convert from CString
to std::wstring
?
Convert CString to std::wstring
Please see this: #258550 –
Ambiversion
and #859804 –
Librettist
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());
This should work as CString
has operator LPCTSTR()
defined:
CString s;
std::wstring s1 = s;
Try this:
std::wstring strString((LPCTSTR)strCString);
Why use a C cast for that? A fellow-worker of mine once was in the position that he had to find explicit casts, as some of them didn't work on the platform he needed to port a 4MLoC project to. He praised everyone who used C++' explicit casts (you can grep for them) and fought hard to ban all C-style casts, since they were so hard to find. –
Usk
CString s = _T("Привет");
USES_CONVERSION;
std::wstring ws(A2W((LPCTSTR)s));
© 2022 - 2024 — McMap. All rights reserved.