#include <fstream>
#include <sstream>
#include <iostream>
void print_backwards(std::istream& in)
{
char ch;
if (!in.get(ch)) // base condition: Nothing more to be extracted from stream.
return;
print_backwards(in); // extract more input and print it prior to
std::cout << ch; // printing this character.
}
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"
);
print_backwards(in);
}
I2luY2x1ZGUgPGZzdHJlYW0+CiNpbmNsdWRlIDxzc3RyZWFtPgojaW5jbHVkZSA8aW9zdHJlYW0+Cgp2b2lkIHByaW50X2JhY2t3YXJkcyhzdGQ6OmlzdHJlYW0mIGluKQp7CiAgICBjaGFyIGNoOwogICAgaWYgKCFpbi5nZXQoY2gpKSAgICAgICAgICAgICAgICAgICAgICAgIC8vIGJhc2UgY29uZGl0aW9uOiBOb3RoaW5nIG1vcmUgdG8gYmUgZXh0cmFjdGVkIGZyb20gc3RyZWFtLgogICAgICAgIHJldHVybjsKCiAgICBwcmludF9iYWNrd2FyZHMoaW4pOyAgICAgICAgICAgICAgICAgICAgLy8gZXh0cmFjdCBtb3JlIGlucHV0IGFuZCBwcmludCBpdCBwcmlvciB0bwogICAgc3RkOjpjb3V0IDw8IGNoOyAgICAgICAgICAgICAgICAgICAgICAgIC8vIHByaW50aW5nIHRoaXMgY2hhcmFjdGVyLgp9CgppbnQgbWFpbigpCnsKICAgIC8vIG91ciBtYWtlc2hpZnQgZmlsZSBjb250ZW50cy4gIFJlcGxhY2Ugd2l0aCBzdGQ6Omlmc3RyZWFtIGluKCJmaWxlbmFtZSIpCiAgICBzdGQ6OmlzdHJpbmdzdHJlYW0gaW4oCiAgICAgICAgIkphY2sgYW5kIEppbGwgd2VudCB1cCB0aGUgaGlsbFxuIgogICAgICAgICJUbyBmZXRjaCBhIHBhaWwgb2Ygd2F0ZXJcbiIKICAgICAgICAiSmFjayBmZWxsIGRvd24gYW5kIGJyb2tlIGhpcyBjcm93blxuIgogICAgICAgICJBbmQgSmlsbCBjYW1lIHR1bWJsaW5nIGFmdGVyIgogICAgKTsKCiAgICBwcmludF9iYWNrd2FyZHMoaW4pOwp9Cgo=