fork download
  1. #include <string>
  2. #include <iostream>
  3. #include <iomanip>
  4.  
  5. unsigned to_unsigned(char ch)
  6. {
  7. return static_cast<unsigned>(static_cast<unsigned char>(ch));
  8. }
  9.  
  10. int main()
  11. {
  12. std::cout << "Enter a string: ";
  13.  
  14. std::string line;
  15. std::getline(std::cin, line);
  16.  
  17. for (std::size_t pos = 0; pos < line.size(); ++pos)
  18. {
  19. std::cout << std::setfill(' ');
  20. std::cout << std::setw(2) << line[pos];
  21.  
  22. unsigned ascii = to_unsigned(line[pos]);
  23.  
  24. std::cout << " = " << std::setw(3) << std::dec << ascii;
  25. std::cout << " = 0x" << std::setw(2) << std::hex << std::setfill('0') << ascii;
  26. std::cout << '\n';
  27. }
  28. }
Success #stdin #stdout 0s 3432KB
stdin
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890!@#$%^&*()_+-={}[]\|:";'<>?,./`
stdout
Enter a string:  a =  97 = 0x61
 b =  98 = 0x62
 c =  99 = 0x63
 d = 100 = 0x64
 e = 101 = 0x65
 f = 102 = 0x66
 g = 103 = 0x67
 h = 104 = 0x68
 i = 105 = 0x69
 j = 106 = 0x6a
 k = 107 = 0x6b
 l = 108 = 0x6c
 m = 109 = 0x6d
 n = 110 = 0x6e
 o = 111 = 0x6f
 p = 112 = 0x70
 q = 113 = 0x71
 r = 114 = 0x72
 s = 115 = 0x73
 t = 116 = 0x74
 u = 117 = 0x75
 v = 118 = 0x76
 w = 119 = 0x77
 x = 120 = 0x78
 y = 121 = 0x79
 z = 122 = 0x7a
 A =  65 = 0x41
 B =  66 = 0x42
 C =  67 = 0x43
 D =  68 = 0x44
 E =  69 = 0x45
 F =  70 = 0x46
 G =  71 = 0x47
 H =  72 = 0x48
 I =  73 = 0x49
 J =  74 = 0x4a
 K =  75 = 0x4b
 L =  76 = 0x4c
 M =  77 = 0x4d
 N =  78 = 0x4e
 O =  79 = 0x4f
 P =  80 = 0x50
 Q =  81 = 0x51
 R =  82 = 0x52
 S =  83 = 0x53
 T =  84 = 0x54
 U =  85 = 0x55
 V =  86 = 0x56
 W =  87 = 0x57
 X =  88 = 0x58
 Y =  89 = 0x59
 Z =  90 = 0x5a
 0 =  48 = 0x30
 1 =  49 = 0x31
 2 =  50 = 0x32
 3 =  51 = 0x33
 4 =  52 = 0x34
 5 =  53 = 0x35
 6 =  54 = 0x36
 7 =  55 = 0x37
 8 =  56 = 0x38
 9 =  57 = 0x39
 0 =  48 = 0x30
 ! =  33 = 0x21
 @ =  64 = 0x40
 # =  35 = 0x23
 $ =  36 = 0x24
 % =  37 = 0x25
 ^ =  94 = 0x5e
 & =  38 = 0x26
 * =  42 = 0x2a
 ( =  40 = 0x28
 ) =  41 = 0x29
 _ =  95 = 0x5f
 + =  43 = 0x2b
 - =  45 = 0x2d
 = =  61 = 0x3d
 { = 123 = 0x7b
 } = 125 = 0x7d
 [ =  91 = 0x5b
 ] =  93 = 0x5d
 \ =  92 = 0x5c
 | = 124 = 0x7c
 : =  58 = 0x3a
 " =  34 = 0x22
 ; =  59 = 0x3b
 ' =  39 = 0x27
 < =  60 = 0x3c
 > =  62 = 0x3e
 ? =  63 = 0x3f
 , =  44 = 0x2c
 . =  46 = 0x2e
 / =  47 = 0x2f
 ` =  96 = 0x60