Advertisement
Guest User

Untitled

a guest
Jan 21st, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. #ifndef READ_NUMBER_HPP_
  2. #define READ_NUMBER_HPP_
  3.  
  4. #include <string>
  5. #include <iostream>
  6. #include <limits>
  7.  
  8. template <typename T>
  9. void readNumber(std::wstring err_msg, T & number)
  10. {
  11.     while(true)
  12.     {
  13.         while(!(std::wcin >> number))
  14.         {
  15.             std::wcout << number << std::endl;
  16.             std::wcout << err_msg << std::endl;
  17.             std::wcin.clear();
  18.             std::wcin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
  19.         }
  20.         if(number > 0)
  21.         {
  22.             std::wcin.clear();
  23.             std::wcin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
  24.             break;
  25.         }
  26.         std::wcout << err_msg << std::endl;
  27.     }
  28. }
  29.  
  30. #endif //READ_NUMBER_HPP_
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement