I want to convert LPTSTR to string or char * to be able to write it to file using ofstream.
Any Ideas?
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.
Most solutions presented in the other threads unnecessarily convert to an obsolete encoding instead of an Unicode encoding. Simply use
reinterpret_cast<const char*>to write UTF-16 files, or convert to UTF-8 usingWideCharToMultiByte.To depart a bit from the question, using
LPTSTRinstead ofLPWSTRdoesn’t make much sense nowadays since the old 9x series of Windows is completely obsolete and unsupported. Simply useLPWSTRand the accompanying “wide character” (i.e., UTF-16 code unit) types likeWCHARorwchar_teverywhere.Here is an example that (I hope) writes UTF-16 or UTF-32 (the latter on Linux/OS X):