tags:

views:

379

answers:

3

Can any one tell me how to convert CString to std::wstring

A: 
CString s;
std::wstring s1 = s;

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

Naveen
A: 
try out this :

std::wstring strString((LPCTSTR)strCString)
Ashish
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.
sbi
+1  A: 
CString hi("Hi");
std::wstring hi2(hi);

to go the other way, use c_str()

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