#include <fstream>
#include <sstream>
#include <iostream>
#include <string>
#include <deque>
#include <algorithm>

int main()
{
    // our makeshift file contents.  Replace with std::ifstream in("filename")
    std::istringstream in(
        "Jack and Jill went up the hill\n"
        "To fetch a pail of water\n"
        "Jack fell down and broke his crown\n"
        "And Jill came tumbling after\n"
    );

    std::deque<std::string> lines;      

    {
        std::string line;
        while (std::getline(in, line))                  // get a line.
        {
            std::reverse(line.begin(), line.end());     // reverse it.
            lines.push_front(line);                     // store it in our container.
        }
    }

    for (auto& line : lines)                     
        std::cout << line << '\n';
}
