There is a variable of the string type, the string entered by the user from the keyboard is written to it. It is necessary to calculate the sum of all numbers in this line.
The problem is that it is not possible to translate a character digit into a digital digit. I tried using the atoi function, but it gives the wrong result.
My code is:
string s; //code code... cin>>s; //code code... for(int i=0;i<s.length();i++) { cout<<s[i]<<" "; if((int)s[i]>47 && (int)s[i]<58) { count++; sum+=atoi(&s[i]); } }