This is how atoi() is used, basically.
#include <cstdlib>
#include <iostream>
int main()
{
using namespace std;
int a = atoi("10");
cout << a << " squared is " << a * a << '\n';
}
The basic use isn't enough unless you can guarantee that the string represents both an integer value and an integer value that fits in the range of int. If you can't guarantee that, atoi() doesn't do a good job of handling those kinds of errors.
One problem with atoi() is that it returns 0 if an error occurs. 0 is a valid integer so unless you want to ban 0 in your program, you can't reliably use it as an error indicator.
Another problem is that if the number can't be represented by int, the behavior of atoi() is undefined and there's no way around it without pre-validating the string.
The end result is that a robust use of atoi() looks more like this:
int main()
{
using namespace std;
char *s;
// Initialize s and fill it with a string
if (IsInt(s)) {
int a = atoi(s);
cout << a << '\n';
}
}
Where IsInt() is a function you write that validates the string to make sure the represented value fits in an int. The other ways of converting a char* to int may be more verbose, but they're also more user friendly when it comes to error handling.
Edward recommends that you only use atoi() when there's a 100% guarantee that the string represents a valid int and no error handling will ever be necessary.