How To: Convert Text To Numbers In C++
This example shows how to convert a character string of digits
and an optional decimal point into a number. The number can be
an integer or a floating point value.
#include <iostream>
using std::cout;
using std::endl;
#include <cstdlib>
int main()
{
char* token[] = {"100.23", "4", "one"};
double a = atof(token[0]); // a floating point
int b = atoi(token[1]); // an integer
double c = atof(token[2]); // non-numerics returns as zero
cout << "atof(token[0]) = " << a << endl;
cout << "atoi(token[1]) = " << b << endl;
cout << "atof(token[2]) = " << c << endl;
return 0;
}