Jump to content
  • Advertisement
Sign in to follow this  
Servant of the Lord

Converting a float to a string?

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

I'm having trouble with this. I can use the gcvt(double value, int num, char* buffer); but I want to pass a string to char* buffer. I use .c_str(), but I get a error as "invalid conversion from 'const char*' to 'char*'". How do I now convert this? Thanks,

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
You cant do that - theres a reason the c_str() returns a const char* and not a char*. Use stringstream instead. http://www.cppreference.com/cppsstream/index.html

Share this post


Link to post
Share on other sites
You can either do a const_cast if you know that the string won't be modified (<-- not correct way to go about it) or you can just copy the contents of the the const char* into a char*.

Share this post


Link to post
Share on other sites
oh n/m you are going from float to string. heh. so then also check out the sprintf variants. use the ones you can pass the size of your string into so you don't screw stuff up. ;)

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!