Link to home
Start Free TrialLog in
Avatar of sparkythedog
sparkythedogFlag for Canada

asked on

Convert Unicode CString to STL::string

How to convert an Unicode CString to STL::string?

Thanks
Avatar of jkr
jkr
Flag of Germany image

If you need an ANSI string:

CString strUni = L"Test";

size_t len = strUni.GetLength() + 1;
char* psz = new char[len];
wcstombs(psz,(LPCTSTR)strUni,len);

std::string str = psz;

delete [] psz;
Avatar of sparkythedog

ASKER

Hi there,
thanks for your reply

I need the STL string to contain the UNICODE string from CString.

Thanks
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial