Jump to content
  • Advertisement
Sign in to follow this  

How to convert a string to a LPTSTR?

This topic is 4901 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Assuming that by "LPTSTR" you mean a char* (call things by their proper names, damnit) then the answer is not quite.

std::string::c_str() will return a const char*.

If you are dying for a char*, you can either copy out the string to a buffer using std::string::copy(), or take your chances and cast away the constness with a const_cast<char*>. Of course, modifying the string that way may break everything. You're on your own if that's what you decide to do.

Now, since you mentioned LPTSTR, and since the "T" in LPTSTR seems to imply you are using MS' TCHAR typedef, you'll want to either use std::string or std::wstring, depending on whether TCHAR resolves to char or wchar_t.

In fact, you might as well get used to using std::basic_string<TCHAR>. Or better, make a typedef for it. In fact, there might already be one conveniently defined for you in <tchar.h> (I think that's what the header is - not being part of standard C++, I'm not sure).

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!