daily pastebin goal
77%
SHARE
TWEET

Untitled

a guest Jan 20th, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <string>
  3. #include <cctype>
  4. void check_isspace(char ch, std::string desc)
  5. {
  6.     if(std::isspace(ch))
  7.         std::cout << desc << " is a space" << std::endl;
  8.     else
  9.         std::cout << desc << " is not a space" << std::endl;
  10. }
  11.  
  12. int main()
  13. {
  14.     // passing characters
  15.     check_isspace(' ', "space"); // space
  16.     check_isspace('\t', "tab"); // tab
  17.     check_isspace('\v', "vertical tab"); // vertical tab
  18.     check_isspace('\n', "new line"); // new line
  19.     check_isspace('\r', "carriage return"); // carriage return
  20.     check_isspace('\f', "form feed"); // form feed
  21.    
  22.     std::cout << std::endl << "Try again with number represetations instead of char" << std::endl << std::endl;
  23.    
  24.     // passing int values in place of chars
  25.     check_isspace(0x20, "space"); // space
  26.     check_isspace(0x09, "tab"); // tab
  27.     check_isspace(0x0b, "vertical tab"); // vertical tab
  28.     check_isspace(0x0a, "new line"); // new line
  29.     check_isspace(0x0d, "carriage return"); // carriage return
  30.     check_isspace(0x0c, "form feed"); // form feed
  31.    
  32.     std::cout << std::endl << "Try non-space chars" << std::endl << std::endl;
  33.    
  34.     // check few numbers
  35.     check_isspace(5, "number"); // number
  36.     check_isspace(55.99, "decimal number"); // decimal number
  37.    
  38.     // check few non-space chars
  39.     check_isspace('a', "char a"); // char 1
  40.     check_isspace(0x01, "ascii char 01"); // ascii char 1
  41.    
  42.     std::cout << std::endl << "IMPORTANT: floating value is considered as space. Reason: 11.99 becomes 11 when assigned to char parameter, which is line feed(\n)." << std::endl << std::endl;
  43.     check_isspace(11.99, "decimal number"); // IMPORTANT! decimal number
  44.    
  45.     return 0;
  46. }
  47.  
  48.  
  49. /*********** Output **********
  50. space is a space
  51. tab is a space
  52. vertical tab is a space
  53. new line is a space
  54. carriage return is a space
  55. form feed is a space
  56.  
  57. Try again with number represetations instead of char
  58.  
  59. space is a space
  60. tab is a space
  61. vertical tab is a space
  62. new line is a space
  63. carriage return is a space
  64. form feed is a space
  65.  
  66. Try non-space chars
  67.  
  68. number is not a space
  69. decimal number is not a space
  70. char a is not a space
  71. ascii char 01 is not a space
  72.  
  73. IMPORTANT: floating value is considered as space. Reason: 11.99 becomes 11 when assigned to char parameter, which is line feed(
  74. ).
  75.  
  76. decimal number is a space
  77.  
  78. */
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top