How do I convert a TCHAR array to std::string (not to std::basic_string)?
How do I convert a TCHAR array to std::string (not to std::basic_string )?
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.
TCHARis just a typedef that, depending on your compilation configuration, either defaults tocharorwchar_t.Standard Template Library supports both ASCII (with
std::string) and wide character sets (withstd::wstring). All you need to do is to typedef String as either std::string or std::wstring depending on your compilation configuration. To maintain flexibility you can use the following code:Now you may use
Stringin your code and let the compiler handle the nasty parts. String will now have constructors that lets you convertTCHARtostd::stringorstd::wstring.