function - C++ : What is the usage of int('0') in this code? -


this question has answer here:

this code find sum of digits occur in string.

example

sumupnumbers("2 apples, 12 oranges") = 5 //2+1+2

can explain need use int('0') in code!?

int sumupdigits(std::string inputstring) {    int answer = 0;    (int = 0; < inputstring.size(); i++) {       if ('1' <= inputstring[i] && inputstring[i] <= '9') {       answer += int(inputstring[i]) - int('0');     }   }    return answer; } 

it converts char ascii code make number out of string

int('9') - int('0') = 9 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -