String type Go LPCTSTR

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.