Jump to content
  • Advertisement
Sign in to follow this  
Moe

Quick question: float-LPCSTR conversion...

This topic is 4830 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 all, I have a super quick question for you all. It has been a while since I have ussed C++, and I am not really too familiar with type coversions. I have a float and some text that I need to covert into a LPCSTR so that I can output it properly to the screen. How does one go about doing this? I had a quick chat on the GDNet Chat Network, but wasn't able to come up with a working solution (yet!). Anyone?

Share this post


Link to post
Share on other sites
Advertisement
You can either use boost::lexical_cast or a std::stringstream.

std::stringstream sstr;
sstr << my_int;
LPCSTR ptr1 = sstr.str().c_str();

std::string str = boost::lexical_cast<std::string>(my_int);
LPCSTR ptr2 = str.c_str();

Share this post


Link to post
Share on other sites
What particular files do I need to #include (or do I need to do anything special in that regard)?

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!