Traversing the string
for ( int i = 0 ; i < num . size ( ) ; i ++ ) { if ( i % 2 == 0 ) sumOdd = sumOdd + ( int ( num [ i ] ) - 48 ) ; else sumEven = sumEven + ( int ( num [ i ] ) - 48 ) ; } cout << " Sum ▁ odd ▁ = ▁ " << sumOdd << " STRNEWLINE " ; cout << " Sum ▁ even ▁ = ▁ " << sumEven << " STRNEWLINE " ; }