Sign in to follow this  

converting float to char* in C++

This topic is 4287 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
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
Sign in to follow this