Sunday, August 2, 2009

How do you convert string into float c++?

If I have a character array:





char a[]={"92*43-2*2/+"};





How would I convert each number in this array to a float?





I've attempted different methods but I end up getting the decimal value for the ascii character.





For example converting 0 to a float I end up with 48.

How do you convert string into float c++?
You would have to write a function to parse the string into its numbers and operators.





Then you would have to write code to apply the operators to the numbers, making sure to use the proper prescendence.





I have no idea how to interpret that "/+" at the end of the string.
Reply:That isn't converting a string to float, it is processing a command string of calculator commands, which is much more.


This would be a string that could be converted to float by skipping the first character "$12345.65"


No comments:

Post a Comment