jack06215

[tools] numberic / float checker

Jul 8th, 2020 (edited)
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.50 KB | None | 0 0
  1. bool isNumeric(const char* pszInput, int nNumberBase)
  2. {
  3.     std::string base = "0123456789ABCDEF";
  4.     std::string input = pszInput;
  5.  
  6.     return (input.find_first_not_of(base.substr(0, nNumberBase)) == std::string::npos);
  7. }
  8.  
  9. bool isFloat(std::string myString)
  10. {
  11.     std::istringstream iss(myString);
  12.     float f;
  13.     iss >> std::noskipws >> f;  // noskipws considers leading whitespace invalid
  14.                                 // Check the entire string was consumed and if either failbit or badbit is set
  15.     return iss.eof() && !iss.fail();
  16. }
Add Comment
Please, Sign In to add comment