Sign in to follow this  
matrisking

converting float to char* in C++

Recommended Posts

matrisking    282
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
Enigma    1410
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this