#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';
}
I2luY2x1ZGUgPGZzdHJlYW0+CiNpbmNsdWRlIDxzc3RyZWFtPgojaW5jbHVkZSA8aW9zdHJlYW0+CiNpbmNsdWRlIDxzdHJpbmc+CiNpbmNsdWRlIDxkZXF1ZT4KI2luY2x1ZGUgPGFsZ29yaXRobT4KCmludCBtYWluKCkKewogICAgLy8gb3VyIG1ha2VzaGlmdCBmaWxlIGNvbnRlbnRzLiAgUmVwbGFjZSB3aXRoIHN0ZDo6aWZzdHJlYW0gaW4oImZpbGVuYW1lIikKICAgIHN0ZDo6aXN0cmluZ3N0cmVhbSBpbigKICAgICAgICAiSmFjayBhbmQgSmlsbCB3ZW50IHVwIHRoZSBoaWxsXG4iCiAgICAgICAgIlRvIGZldGNoIGEgcGFpbCBvZiB3YXRlclxuIgogICAgICAgICJKYWNrIGZlbGwgZG93biBhbmQgYnJva2UgaGlzIGNyb3duXG4iCiAgICAgICAgIkFuZCBKaWxsIGNhbWUgdHVtYmxpbmcgYWZ0ZXJcbiIKICAgICk7CgogICAgc3RkOjpkZXF1ZTxzdGQ6OnN0cmluZz4gbGluZXM7ICAgICAgCgogICAgewogICAgICAgIHN0ZDo6c3RyaW5nIGxpbmU7CiAgICAgICAgd2hpbGUgKHN0ZDo6Z2V0bGluZShpbiwgbGluZSkpICAgICAgICAgICAgICAgICAgLy8gZ2V0IGEgbGluZS4KICAgICAgICB7CiAgICAgICAgICAgIHN0ZDo6cmV2ZXJzZShsaW5lLmJlZ2luKCksIGxpbmU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