fork download
  1. #include <iostream>
  2. #include <iterator>
  3. #include <algorithm>
  4.  
  5. bool isNumber( const std::string& s )
  6. {
  7. for( std::string::const_iterator it=s.begin(); it!=s.end(); ++it )
  8. {
  9. if( !std::isdigit(*it) ) return false;
  10. }
  11. return true;
  12. }
  13.  
  14. bool printNumbersOnly( std::istream_iterator<std::string>& it )
  15. {
  16. bool nothing = true;
  17. std::istream_iterator<std::string> eos;
  18. while( it != eos )
  19. {
  20. if( *it == "end" ) break;
  21. if( isNumber(*it) )
  22. {
  23. nothing = false;
  24. std::cout << *it << std::endl;
  25. }
  26. ++it;
  27. }
  28. return !nothing;
  29. }
  30.  
  31. int main() {
  32. std::istream_iterator<std::string> iit(std::cin);
  33. if( !printNumbersOnly( iit ) ) std::cout << "nothing\n";
  34. return 0;
  35. }
Success #stdin #stdout 0s 3036KB
stdin
I have a 3sons
and1 son and 25dogs
end 
1 he he
stdout
nothing