fork(1) download
  1. #include <string>
  2. #include <cctype>
  3. #include <iostream>
  4.  
  5. void printCharsAsHex(std::ostream& os, const std::string& s)
  6. {
  7. for (auto ch : s)
  8. if (ch != ' ' && !std::ispunct(ch))
  9. os << std::hex << (int) ch;
  10. else
  11. os << ch; // A space is a space.
  12.  
  13. os << '\n' ;
  14. }
  15.  
  16. int main()
  17. {
  18. std::string line;
  19.  
  20. while (std::getline(std::cin, line))
  21. printCharsAsHex(std::cout, line);
  22. }
Success #stdin #stdout 0s 3432KB
stdin
hello
My name is Satan.  I mean Stan.
stdout
68656c6c6f
4d79 6e616d65 6973 536174616e.  49 6d65616e 5374616e.