Sign in to follow this  

Help with std::string

This topic is 4791 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

Hey guys I was wondering if any of you knew how to change a std::string to an LPCSTR. All of my string data is stored as a std::string but the function I need to use will only work with and LPCSTR. Any help would be greatly appreciated. BTW The function Iam trying to use is the ID3DXFont::DrawText.

Share this post


Link to post
Share on other sites
Do you know what an LPCTSTR is a typedef for? const char *. Do you know what member of std::string returns a const char *? c_str.
std::string aString;
void SomeFunction(LPCTSTR param);

...

SomeFunction(aString.c_str());

Happy hacking!

Share this post


Link to post
Share on other sites
Use the .c_str() member:

std::string str;
LPCSTR lps = str.c_str();




regards,
Pat.

[edit]
Too slow...[smile]
[/edit]

Share this post


Link to post
Share on other sites
string str = "This is a string";
LPCSTR cstr = str.c_str();



Basically, the c_str() method of the string class return a const char *, and an LPCSTR is the same thing (long pointer to a constant string).

Regards,
jflanglois

[edit] Hmph, beaten

Share this post


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