Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Vs20 10 prompts error C2440: "=": unable to convert from "wchar_t *" to "char *", please solve.
Vs20 10 prompts error C2440: "=": unable to convert from "wchar_t *" to "char *", please solve.
The type returned by CString::GetBuffer () is LPTSTR.

Let's look at the definition of LPTSTR:

& ltWINNT。 H & gt

#ifdef UNICODE // r_winnt

typedef LPWSTR PTSTR,LPTSTR

#else /* UNICODE */ // r_winnt

typedef LPSTR PTSTR,LPTSTR

#endif /* UNICODE */ // r_winnt

View the definitions of LPWSTR and LPSTR:

& ltWINNT。 H & gt

#ifndef _MAC

Typedef wchar _ t WCHAR// wc, 16 UNICODE characters.

# Otherwise

Typedef unsigned short WCHAR// wc, 16 UNICODE characters.

#endif

typedef WCHAR *LPWSTR,* PWSTR

-that is, LPWSTR is wchar_t* or unsigned*

typedef char CHAR

typedef CHAR *LPSTR,* LPSTR

-that is, LPSTR is char*

The two definitions are inconsistent and cannot be assigned directly.

The reason is that when you create a project (which may be the default), you choose UNICODE mode.

There are two kinds of modifications: one is to remove the UNICODE mode.

The second one is

Char * pstr changes the definition to LPTSTR pstr. This can also use printf () or MessageBox () output, allowing multi-byte non-ASCII characters. (The function is basically unaffected)