fork download
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. int toInteger(const string& str, int count,int&value){
  6. if(str.length() == 1) {
  7. value += (str[0] - '0')*pow(10,count);
  8. return value;
  9. }
  10. else{
  11. value +=(str[str.length()-1] - '0')*pow(10,count);
  12. cout << value << endl << str << endl;
  13. toInteger(str.substr(0,str.length()-1),count+1,value);
  14. }
  15. return value;
  16. }
  17.  
  18. int main(){
  19. string str;
  20. cout << "Enter String : ";
  21. cin >> str;
  22. int count = 0;
  23. int value = 0;
  24. int toint = toInteger(str, count, value);
  25. cout << toint << endl;
  26. }
Success #stdin #stdout 0s 3236KB
stdin
1234
stdout
Enter String : 4
1234
34
123
234
12
1234