fork download
  1. #include <fstream>
  2. #include <sstream>
  3. #include <iostream>
  4. #include <string>
  5. #include <deque>
  6. #include <algorithm>
  7.  
  8. int main()
  9. {
  10. // our makeshift file contents. Replace with std::ifstream in("filename")
  11. std::istringstream in(
  12. "Jack and Jill went up the hill\n"
  13. "To fetch a pail of water\n"
  14. "Jack fell down and broke his crown\n"
  15. "And Jill came tumbling after\n"
  16. );
  17.  
  18. std::deque<std::string> lines;
  19.  
  20. {
  21. std::string line;
  22. while (std::getline(in, line)) // get a line.
  23. {
  24. std::reverse(line.begin(), line.end()); // reverse it.
  25. lines.push_front(line); // store it in our container.
  26. }
  27. }
  28.  
  29. for (auto& line : lines)
  30. std::cout << line << '\n';
  31. }
  32.  
Success #stdin #stdout 0s 3476KB
stdin
Standard input is empty
stdout
retfa gnilbmut emac lliJ dnA
nworc sih ekorb dna nwod llef kcaJ
retaw fo liap a hctef oT
llih eht pu tnew lliJ dna kcaJ