fork(1) download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. std::string escape_control_characters(const std::string & s)
  5. {
  6. std::string ret;
  7. for(std::string::const_iterator iter = s.begin(); iter != s.end(); ++iter)
  8. {
  9. const char c = *iter;
  10. if(c < ' ')
  11. {
  12. ret.push_back('^');
  13. ret.push_back(c + '@');
  14. }
  15. else if(c == '\x7F')
  16. ret.append("^?");
  17. else
  18. ret.push_back(c);
  19. }
  20. return ret;
  21. }
  22.  
  23. int main()
  24. {
  25. std::string tmp;
  26. for(int i = 0; i < 128; ++i)
  27. tmp.push_back(i);
  28. std::cout << escape_control_characters(tmp) << std::endl;
  29. return 0;
  30. }
  31.  
Success #stdin #stdout 0.02s 2812KB
stdin
Standard input is empty
stdout
^@^A^B^C^D^E^F^G^H^I^J^K^L^M^N^O^P^Q^R^S^T^U^V^W^X^Y^Z^[^\^]^^^_ !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~^?