Implement atoi to convert a string to an integer.
详细的转换方法在此处点击打开链接
思路:使用流操作
class Solution {
public:
int myAtoi(string str) {
stringstream ss; //在vs2013中 需要设置为 strstream ss; #include<strstream>
ss << str;
int n;
ss >> n;
return n;
}
};