fork download
  1. #include <iostream>
  2. #include <memory>
  3. #include <string>
  4. #include <vector>
  5. #include <algorithm>
  6.  
  7.  
  8. int main() {
  9.  
  10. std::string str = "Hello World";
  11. std::vector<unsigned long int> keys;
  12.  
  13. // forward
  14. for(std::string::iterator it = str.begin(); it != str.end(); ++it) {
  15. unsigned long int c = (unsigned long int) (*it);
  16. keys.push_back(c);
  17. }
  18.  
  19. for(unsigned long int x : keys) {
  20. std::cout << (char)x;
  21. }
  22.  
  23. std::cout << std::endl;
  24.  
  25. keys.clear();
  26.  
  27.  
  28. // reverse
  29. for(std::string::reverse_iterator it = str.rbegin(); it != str.rend(); ++it) {
  30. unsigned long int c = (unsigned long int) (*it);
  31. keys.push_back(c);
  32. }
  33.  
  34.  
  35. for(unsigned long int x : keys) {
  36. std::cout << (char)x;
  37. }
  38.  
  39. return 0;
  40. }
Success #stdin #stdout 0s 3228KB
stdin
Standard input is empty
stdout
Hello World
dlroW olleH