How can I convert a string from wchar_t to LPSTR.
How can I convert a string from wchar_t to LPSTR .
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A
wchar_tstring is made of 16-bit units, aLPSTRis a pointer to a string of octets, defined like this:What’s important is that the LPSTR may be null-terminated.
When translating from
wchar_ttoLPSTR, you have to decide on an encoding to use. Once you did that, you can use theWideCharToMultiBytefunction to perform the conversion.For instance, here’s how to translate a wide-character string into UTF8, using STL strings to simplify memory management:
You could use this function to translate a
wchar_t*toLPSTRlike this: