string str; int ans = 0; int currPower = 0; for(int i = str.size()-1; i >= 0; i--){ ans += (str[i] - '0') * pow(10,currPower); currPower++; }