Today when writing MFC, I found that the type of the MessageBox function is LPCTSTR, and I use the C + + STL String type can not go directly, so I found a function on the internet for conversion
Std::wstring stows (ConstSTD::string&s) { intLen;intSlength = (int) s.length () +1; Len= MultiByteToWideChar (CP_ACP,0, S.c_str (), Slength,0,0); wchar_t* BUF =NewWchar_t[len]; MultiByteToWideChar (CP_ACP,0, S.c_str (), Slength, buf, Len); Std::wstring R (BUF); Delete[] BUF; returnR;} STD::strings; if it is a UNICODE character: std::wstring stemp=stows (s); LPCWSTR result=stemp.c_str (); If not: lpcwstr result= S.c_str ();
Also enclosed is a table of correspondence type
LPSTR-(Long) Pointer tostring-Char*LPCSTR- (Long) Pointer to constantstring-Const Char*LPWSTR- (Long) pointer to Unicode (wide)string-wchar_t *LPCWSTR- (Long) Pointer to constant Unicode (wide)string-Constwchar_t *LPTSTR- (Long) pointer to TCHAR (UnicodeifUnicode isDefined, ANSIifNotstring-TCHAR *LPCTSTR- (Long) Pointer to constant TCHARstring-ConstTCHAR *
String type Go LPCTSTR