fork download
  1. #include <iostream>
  2.  
  3. template <typename Iter>
  4. void reverse(Iter first, Iter last)
  5. {
  6. while (first != last && first != --last) {
  7. std::swap(*first, *last);
  8. first++;
  9. }
  10. }
  11.  
  12. int main()
  13. {
  14. std::string str("12345");
  15. reverse(str.begin(), str.end());
  16. std::cout << str;
  17. return 0;
  18. }
Success #stdin #stdout 0s 3028KB
stdin
Standard input is empty
stdout
54321