Quick question: float-LPCSTR conversion...

Started by
3 comments, last by Moe 18 years, 7 months ago
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?
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();
What particular files do I need to #include (or do I need to do anything special in that regard)?
Include sstream for stringstream. You'd need to get the boost library for boost::lexical_cast.
Ah, excellent! Thanks a bunch (again) SiCrane!

This topic is closed to new replies.

Advertisement