If you want to reverse the whole file this will do it -
Code:
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
string filenameOld;
string filenameNew;
string text;
vector <string> strs;
cout << "What file do you want to backwardsify?\n";
getline(cin,filenameOld, '\n');
cout << "What do you want the new file to be called?\n";
getline(cin,filenameNew,'\n');
ifstream a_file(filenameOld.c_str());
ofstream b_file(filenameNew.c_str());
if(a_file.fail() || b_file.fail())
{
cout << "Unable to open files\n";
return 1;
}
do
{
getline(a_file,text,'\n');
reverse(text.begin(),text.end());
strs.push_back(text);
cout<<".";
}
while (a_file.eof()!=1);
reverse(strs.begin(),strs.end());
for (int j =0;j<strs.size();j++)
b_file << strs[j] << endl;
cout<<"DONE\n";
return 0;
}
but if you only want to reverse each line then you won't need to store the strings in a vector and could just ouput each line after it has been reversed in the initial loop.