Guest User

Untitled

a guest
Jun 18th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. template<typename T>
  2. void checkInput(T& x) {
  3. while(cin.fail()) {
  4. std::cin.clear(); //Clear all the flags
  5. std::cin.ignore(std::numeric_limits<std::streamsize>::max(), 'n'); // Throw away the rest of the line
  6. std::cout<<"Wrong entry type, enter the correct type input as suggested : " << std::endl;
  7. std::cin >> x;
  8. }
  9. }
  10.  
  11.  
  12. int main() {
  13.  
  14. char ch;
  15.  
  16. std::cout<<"Input a single Character, followed by : ";
  17. std::cin >> ch; checkInput(ch);
  18.  
  19. std::cout<<std::endl<<"User input character is t" << ch;
  20.  
  21. }
  22.  
  23. Input a single Character, followed by : abc
  24. User input character is a
  25.  
  26. Input a single Character, followed by : 123
  27. User input character is 1
Add Comment
Please, Sign In to add comment