Your problem is that you use string but the atoi needs const char *.
int atoi ( const char * str );
You should use the c_str function of the string class. I.e:
int number = atoi(str.c_str());
You should check the conversion!
On success, the function returns the converted integral number as an int value.
If no valid conversion could be performed, a zero value is returned.
If the correct value is out of the range of representable values, INT_MAX or INT_MIN is returned."