here is the question: "write a program , which has as content "time is a great teacher but unfortunately it kills all its pupils"
and outputs th reverse string to the disk file out.txt.

My problem is that im stuck with the part on how to display the sentence in reverse anyone to help me with the codes?


#include <iostream>
#include <fstream>

using namespace std;

int main()
   char a[100];

   ofstream f("out.txt");

   f<<"time is a great teacher but unfortunately it kills all its pupils ";

   ifstream f1("out.txt");
char ch;

        cout <<ch;


return 0;

you can use array or queue to store the output characters and then you can display those characters.
or you can directly reverse the string

MyStr = inputbox("Enter the String:")
nCnt = Len(MyStr)

For i = 1 to nCnt

   RevStr = Mid(MyStr,i,1)&RevStr


Msgbox RevStr

Trying and use string objects from the #include <string> rather than a char array, because you can revrse a string object in one line of code.

#include <string>
#include <iostream>

int main()
    /*This is just a quick example you will need to load the string from the file just like you did with the char array.*/
    std::string reverse = "Backwards";

    /*String is a constructor of a string which creates a new string, begin and rend reverses the iterator*/
    reverse = std::string(reverse.rbegin(), reverse.rend());

    std::cout << reverse << std::endl;

    return 0;
This question has already been answered. Start a new discussion instead.