Reverse file

I am trying to display contents of a file backwards. However once I get to
vector <string> :: reverse_iterator rit; in main then nothing happens. It will display the { from the cerr but nothing after that. Any help would be great.

/***********************************************************************
* Program:
* Assignment 46, Reverse File
* Brother Helfrich, CS165
* Author:
* Hunter Marshall
* Summary:
* Write a program to read datat from a file line-by-line.
* You will need to store the contents of the file in one of the
* STL containers. Next, dislay the file backwards.
*
*
*
* Estimated: 1.0 hrs
* Actual: 0.0 hrs
* Please describe briefly what was the most difficult part.
************************************************************************/

#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <list>
using namespace std;

void readFile(const string fileName, vector <string> data)
{
ifstream fin(fileName.c_str());
if (fin.fail())
{
cout << "ERROR: Unable to open the file " << fileName << endl;
return;
}

// read the file
string text;
while (fin >> text)
{
data.push_back(text);
}

// close the file and bail
fin.close();
return;
}

/**********************************************************************
* Add text here to describe what the function "main" does. Also don't forget
* to fill this out with meaningful text or YOU WILL LOSE POINTS.
***********************************************************************/
int main()
{
vector <string> data;

string fileName;
cout << "Enter the name of the file: ";
cin >> fileName;

readFile(fileName,data);

cerr << "}\n";

vector <string> :: reverse_iterator rit;
cerr << "here";
for (rit = data.rbegin(); rit != data.rend(); rit++)
cout << *rit;

return 0;
}
Last edited on
void readFile( const string fileName, vector<string> data );
What is the difference between by value and by reference?
Topic archived. No new replies allowed.