Hi,
I am working through a few small C++ projects, one of which is read the contents of a file (a few lines, say 1,2,3) and output them in reverse order to another file.
I am new to C++, and have looked through quite a few resources about getline, read, peek, etc etc but can't nail the problem on the head. I can retrieve the whole contents, the first line or the last line but can't get data line by line !
If someone could point me in the right direction as to the right commands and so forth, and how to grab and store the data in reverse order it would be greatly appreciated.
Regards,
Liam.
my code so far:
#include <iostream.h>
#include <fstream.h>
int main()
{
char buffer[256];
ifstream source ("liam.txt");
while (! source.eof() )
{
source.read (buffer,100);
}
ofstream target ("output.txt");
if (target.is_open())
{
target << buffer;
target.close();
}
return 0;
}