Converting string to integer

here can we convert numeric string to integer like this but it is not producing correct output :-
int ans = 0;
int p = 1;
for(int i=0; i<=s.length()-1; i++){
ans = (s[i]-‘0’) + ans * p;
p *= 10;
}
Please tell what is wrong in this

Hey @Sakshi2004

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.