Here is the code for a leetcode algorithm problem:
class Solution {
public:
int myAtoi(string str) {
if(str == NULL || str.length() == 0) return 0;
int pos = true;
int result = 0;
int i = 0;
if(str.charAt(0) == '+' || str.charAt(0) == '-') {
++i;
if(str.charAt(0) == '-') pos = false;
}
for(; i != str.length(); ++i) {
if(str.charAt(i) >= '0' && str.charAt(i) <= '9') {
result = result*10 + (int)(str.charAt(i)-'0');
}
}
if(!pos) result=-result;
if(result > INT_MAX) return INT_MAX;
if(result < INT_MIN) return INT_MIN;
return result;
}
};
And I got a Compile Error
Line 4: no match for ‘operator==’ (operand types are ‘std::string {aka std::basic_string<char>}’ and ‘long int’)
So what's wrong with the code?