fork download
  1. bool UserInput::validate(istream &cinINPUT, int &reINPUT, int a){
  2.  
  3. if ( cin.peek() == '\n'){ // Read next digit in Stream, if it is IS a new line, then error - As stream is not read yet, this is the 1st char of user input
  4. cin.clear(); // clear input cache
  5. cin.ignore(numeric_limits<streamsize>::max(), '\n'); // ignore anything in buffer
  6. return false; // Set return to FAIL
  7.  
  8. }else if ( !(cinINPUT >> reINPUT) ){ // cin >> in1 returns true if it matches data container
  9. cin.clear(); // clear input cache
  10. cin.ignore(numeric_limits<streamsize>::max(), '\n'); // ignore anything in buffer
  11. return false; // Set return to FAIL
  12.  
  13. }else if ( cin.peek() != '\n'){ // Read next digit in Stream, if it is NOT a new line, then error - As stream has been read, this is the 2nd char of user input
  14. cin.clear(); // clear input cache
  15. cin.ignore(numeric_limits<streamsize>::max(), '\n'); // ignore anything in buffer
  16. return false; // Set return to FAIL
  17.  
  18. }else if ( reINPUT > a || reINPUT < 1 ){ // Test if input is out of range
  19. cin.clear(); // clear input cache
  20. cin.ignore(numeric_limits<streamsize>::max(), '\n'); // ignore anything in buffer
  21. return false; // Set return to FAIL
  22.  
  23. }else{
  24. cin.clear(); // clear input cache
  25. cin.ignore(numeric_limits<streamsize>::max(), '\n'); // ignore anything in buffer
  26. return true;} // If everything is cool and it is clean input - Set return to TRUE
  27. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1: error: ‘UserInput’ has not been declared
prog.cpp:1: error: ‘istream’ was not declared in this scope
prog.cpp:1: error: ‘cinINPUT’ was not declared in this scope
prog.cpp:1: error: expected primary-expression before ‘int’
prog.cpp:1: error: expected primary-expression before ‘int’
prog.cpp:1: error: initializer expression list treated as compound expression
prog.cpp:1: error: expected ‘,’ or ‘;’ before ‘{’ token
stdout
Standard output is empty