i have solved multiply two numbers, but i am unable to solve convert string to integer please help
1 question not solved
@agarwalarjit.agarwal hey,start traversing the string and convert each character to digit by subtracting ascii value 0 and than multiply it with 10 and add to ans which was initialise to 0 ,in this way number is formed.
#include<bits/stdc++.h> using namespace std; int print_integer(string s,int answer,int index) { if(index<0) return answer; else answer=answer*10+print_integer(s,answer,index-1); } int main() { string s; cin>>s; int n=s.length(); reverse(s,s+n); print_integer(s,0,n-1); return 0; }
this code is not working for the problem string to integer
please give correct code for this problem, i am stucked