|
In C, sprintf is a very good option. However, this is the C++ forum. C++ has its own mechanisms available that do these things. An OP is not generally looking to change languages as a solution, but is attempting to learn the language associated with the forum in which the question is posted.
It's also somewhat confounding to me that some respondents are still recommending 'atoi', which is a baddie, and recommending that the OP process each character independently. That's what the intended tools are for, and they cover the job more thoroughly than your average coder will be able to do. Simply consider a number represented in scientific notation to get an idea of what I mean.
Compare the code in posts #3 and #8 to that in #12, bearing in mind that the code in #8 is doing it three times, not just once, as an example of handling input in three different forms.
If I were the OP, I'd have grabbed the solution long ago, run with it, and be done with it.
|