fork(2) download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int main() {
  6. std::string str( "dls?d1:s45;=dd-9m0aA7" );
  7.  
  8. bool sign = false;
  9. size_t sum = 0;
  10.  
  11. for( char c : str )
  12. {
  13. if( c == '-' )
  14. sign = true;
  15. else
  16. {
  17. if( isdigit( c ) )
  18. sum += ( c - '0' )*( sign ? -1 : 1 );
  19.  
  20. sign = false;
  21. }
  22. }
  23.  
  24. std::cout << sum;
  25. return 0;
  26. }
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
8