09-15-2005, 07:27 PM
|
#22
|
|
FFR Player
Join Date: Dec 2003
Location: At My House
Posts: 989
|
Re: RE: Re: C++ Help
Quote:
|
Originally Posted by soccr743
Qreepy, you read from the console into the buffer which is in char* format... Then, you would need to convert that to a float in order to use it in calculations.
|
The function to convert a char * to a float is atof, with its only argument a char * and it returns a value of type float. It is found in in the stdlib.h header file. So you would use it like this:
Code:
#include <iostream>
#include <stdlib>
using namespace std;
int main()
{
char asdfString[5] = "54.2";
float asdfFloat;
asdfFloat = atof(asdfString);
return 0;
}
...and Voila, you can then use asdfFloat in calculations. The atoi function is exactly the same as the atof function, but it returns an integer value instead.
__________________
|
|
|