Advertisement Jump to content
Sign in to follow this  
Moe

Quick question: float-LPCSTR conversion...

This topic is 4898 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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!