#include <cstdlib> int atoi( const char *str );
The atoi function converts
str into an integer, and returns that integer.
should start with whitespace or some sort of number, and atoi will stop
str as soon as a non-numerical character has been read. For
int i; i = atoi( "512" ); i = atoi( "512.035" ); i = atoi( " 512.035" ); i = atoi( " 512+34" ); i = atoi( " 512 bottles of beer on the wall" );
All five of the above assignments to the variable
i would result in it being
set to 512.
If the conversion cannot be performed, then atoi will return zero:
int i = atoi( " does not work: 512" ); // results in i == 0
You can use sprintf to convert a number into a string.