fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4. bool isint(const string& s){
  5. size_t i =0;
  6. bool state;
  7. for(;i<s.size();i++){
  8. if (!isdigit(s[i]))return false;
  9. state = true;
  10. }
  11. return state;
  12. }
  13. int main()
  14. {
  15. string a;
  16. cout<<"enter";
  17. cin>>a;
  18. try{
  19. if(!isint(a)){
  20. cout<<"not an int";
  21. }
  22. else{
  23. cout<<"recorded";
  24. }
  25.  
  26. }
  27. catch(...){
  28. cout<<"error";
  29. }
  30.  
  31. }
Success #stdin #stdout 0.01s 5288KB
stdin
45
stdout
enterrecorded