What\'s the C++ way of parsing a string (given as char *) into an int? Robust and clear error handling is a plus (instead of returning zero).
You can use the a stringstream from the C++ standard libraray:
stringstream ss(str);
int x;
ss >> x;
if(ss) { // <-- error handling
// use x
} else {
// not a number
}
The stream state will be set to fail if a non-digit is encountered when trying to read an integer.
See Stream pitfalls for pitfalls of errorhandling and streams in C++.