12345678910111213
std::string s; std::cout << "Enter a string: "; std::cin >> s; int sum = 0; for ( char c : s ) { if ( std::isdigit( c ) ) sum += c - '0'; } std::cout << "sum = " << sum << std::endl;
for ( char c : s )
for each ( char c in s )