Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - (C++) How to convert Cstring into string! VS2005! ! Head shot. Yes! I've been looking for it for days.
(C++) How to convert Cstring into string! VS2005! ! Head shot. Yes! I've been looking for it for days.
The reason for the error is explained in the error message. The string in the CString buffer uses UNICODE characters for 16 bits, while the string contains ANSI standard characters for 8 bits.

There are two ways to solve it:

1, using the conversion function

char *chr=new char[wo。 GetLength()]

WideCharToMultiByte(CP_ACP,0,wo。 GetBuffer(),- 1,chr,wo。 GetLength(),NULL,NULL);

string str = chr

2. It is recommended that you use WSstring, which is a wide character version of string. Its member function is almost exactly the same as String, so you will definitely use it.

wstring str=wo。 GetLength();