here is my code :
#include
#include
#include <bits/stdc++.h>
using namespace std;
long long int string2number(string s , int i , int length ){
if(s.at(i+1)=='\n'){
return s.at(i)-'0' ;
}
long long int ans= (s.at(i)-'0')*pow(10, length-(i+1) ) + string2number(s,i+1 , length);
return ans;
}
int main() {
string s;
cin>>s;
cout<<s;
cout<<string2number( s,0 ,s.length() );
return 0;
}
am getting this error ( for input 1234 ):
terminate called after throwing an instance of ‘std::out_of_range’
what(): basic_string::at: __n (which is 4) >= this->size() (which is 4)