fork(4) download
  1. #include <iostream>
  2. #include <regex>
  3.  
  4. static const std::regex INT_TYPE("[+-]?[0-9]+");
  5. static const std::regex UNSIGNED_INT_TYPE("[+]?[0-9]+");
  6. static const std::regex DOUBLE_TYPE("[+-]?[0-9]+[.]?[0-9]+");
  7. static const std::regex UNSIGNED_DOUBLE_TYPE("[+]?[0-9]+[.]?[0-9]+");
  8.  
  9. bool isIntegerType(const std::string& str_)
  10. {
  11. return std::regex_match(str_, INT_TYPE);
  12. }
  13.  
  14. bool isUnsignedIntegerType(const std::string& str_)
  15. {
  16. return std::regex_match(str_, UNSIGNED_INT_TYPE);
  17. }
  18.  
  19. bool isDoubleType(const std::string& str_)
  20. {
  21. return std::regex_match(str_, DOUBLE_TYPE);
  22. }
  23.  
  24. bool isUnsignedDoubleType(const std::string& str_)
  25. {
  26. return std::regex_match(str_, UNSIGNED_DOUBLE_TYPE);
  27. }
  28.  
  29. int main()
  30. {
  31. std::string unsignedInteger("026564");
  32. std::string integer("-2656");
  33. std::string unsignedDouble("+0.2426564");
  34. std::string Double("-0.24265640");
  35.  
  36.  
  37. std::cout << std::boolalpha;
  38.  
  39. std::cout << unsignedInteger << ": is Unsigned Integer? " << isUnsignedIntegerType(unsignedInteger) << std::endl;
  40. std::cout << integer << ": is Unsigned Integer? " << isUnsignedIntegerType(integer) << std::endl;
  41. std::cout << unsignedDouble << ": is Unsigned Integer? " << isUnsignedIntegerType(unsignedDouble) << std::endl;
  42. std::cout << Double << ": is Unsigned Integer? " << isUnsignedIntegerType(Double) << std::endl;
  43. std::cout << std::endl;
  44.  
  45. std::cout << unsignedInteger << ": is Integer? " << isIntegerType(unsignedInteger) << std::endl;
  46. std::cout << integer << ": is Integer? " << isIntegerType(integer) << std::endl;
  47. std::cout << unsignedDouble << ": is Integer? " << isIntegerType(unsignedDouble) << std::endl;
  48. std::cout << Double << ": is Integer? " << isIntegerType(Double) << std::endl;
  49. std::cout << std::endl;
  50.  
  51. std::cout << unsignedInteger << ": is Unsigned Double? " << isUnsignedDoubleType(unsignedInteger) << std::endl;
  52. std::cout << integer << ": is Unsigned Double? " << isUnsignedDoubleType(integer) << std::endl;
  53. std::cout << unsignedDouble << ": is Unsigned Double? " << isUnsignedDoubleType(unsignedDouble) << std::endl;
  54. std::cout << Double << ": is Unsigned Double? " << isUnsignedDoubleType(Double) << std::endl;
  55. std::cout << std::endl;
  56.  
  57. std::cout << unsignedInteger << ": is Double? " << isDoubleType(unsignedInteger) << std::endl;
  58. std::cout << integer << ": is Double? " << isDoubleType(integer) << std::endl;
  59. std::cout << unsignedDouble << ": is Double? " << isDoubleType(unsignedDouble) << std::endl;
  60. std::cout << Double << ": is Double? " << isDoubleType(Double) << std::endl;
  61. std::cout << std::endl;
  62.  
  63. }
Success #stdin #stdout 0s 3556KB
stdin
Standard input is empty
stdout
026564: is Unsigned Integer? true
-2656: is Unsigned Integer? false
+0.2426564: is Unsigned Integer? false
-0.24265640: is Unsigned Integer? false

026564: is Integer? true
-2656: is Integer? true
+0.2426564: is Integer? false
-0.24265640: is Integer? false

026564: is Unsigned Double? true
-2656: is Unsigned Double? false
+0.2426564: is Unsigned Double? true
-0.24265640: is Unsigned Double? false

026564: is Double? true
-2656: is Double? true
+0.2426564: is Double? true
-0.24265640: is Double? true