Jump to content
  • Advertisement
Sign in to follow this  
matrisking

converting float to char* in C++

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

Is there an easy way to convert a float to char*? I'd like to be able to pass a float to the output stream initializer along with an extension. So, for example, a list of floats with the first number in the list indicates the ID of the list (cannot just name the lists the ID in this case), so I would like to extract the first entry of the list, add a .nmut extention to it, and create an ouput stream for a file called (for example) "2.nmut" Thanks!

Share this post


Link to post
Share on other sites
Advertisement
std::ofstream file((boost::lexical_cast< std::string >(my_float) + "my_extension").c_str());
// or
std::ostringstream convertor;
convertor << my_float << "my_extension";
std::ofstream file(convertor.str().c_str());


Σnigma

Share this post


Link to post
Share on other sites
std::string pi = boost::lexical_cast< std::string >( 3.141592653589f );
const char * as_c_string = pi.c_str();


EDIT: Geeze, didn't even see Enigma had posted that allready :-(. I fail.

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!