fork(2) download
  1. #include <iostream>
  2. #include <sstream>
  3. #include <iomanip>
  4. #include <string>
  5.  
  6. using namespace std;
  7.  
  8. bool readRangedInt(int min, int max, int &dst)
  9. {
  10. string s;
  11. int n;
  12.  
  13. cin >> s;
  14. istringstream iss(s);
  15.  
  16. iss >> n;
  17.  
  18. if(iss.eof() && n >= min && n <= max)
  19. {
  20. dst = n;
  21. return true;
  22. }
  23.  
  24. return false;
  25. }
  26.  
  27. int main(void)
  28. {
  29. int n;
  30. bool result = readRangedInt(1, 9, n);
  31. char *result_text[] = {"Wrong.", "Correct."};
  32. cout << result_text[result] << endl;
  33.  
  34. return 0;
  35. }
Success #stdin #stdout 0.01s 2864KB
stdin
9
stdout
Correct.