C++ Outputting a text file in reverse order : <p>For this program I am writing, I am suppose to be taking in a text file from the command line, reversing the order of everything in the file and then outputting the text into a new text file with "-reverse" attached on to it. The problem I am having is reversing the order of the lines. I've been able to reverse the text but I need help reversing the lines. I've seen suggestions about using vectors but I'm still new to c++ and I believe i'm not suppose to be using vectors just high-level io
For example, filename.txt contains:</p>

<p>abc</p>

<p>edf</p>

<p>dfg</p>

<p>filename-reverse.txt should contain:</p>

<p>gfd</p>

<p>fde</p>

<p>cba</p>

<p>Mine only contains:</p>

<p>cba</p>

<p>fde</p>

<p>gfd</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;cstdlib&gt;
#include &lt;string&gt;
#include &lt;algorithm&gt;
#include &lt;vector&gt;

using namespace std;
/**
 * Reverses the line
*/
void reverseStr(string&amp; x)
{
 reverse(x.begin(), x.end());
}

 int main(int argc, char *argv[])
{

string filename = argv[1];
string filenameCopy = filename;

string reverse = "-reverse";
string reverseFileName;
string reverseLine;

if(filename.rfind(".txt"))//inserts -reverse into existing file name
 {
     reverseFileName = filenameCopy.insert(filenameCopy.length() - 4,reverse);
 } 

string line;
ifstream myfile (filename);
ofstream out(reverseFileName);

if (myfile.is_open())
{
 /*
 vector&lt;string&gt; lines_in_reverse;

 while(getline(myfile,line))
 {
   lines_in_reverse.insert(lines_in_reverse.begin(), line);
 }
 */

 while(getline(myfile,line))
 {
   cout &lt;&lt; line &lt;&lt; endl;

   reverseStr(line);
   cout &lt;&lt; line &lt;&lt; endl;
   out &lt;&lt; line &lt;&lt; endl;
 }
 myfile.close();

 }
 else 
 {
 cout &lt;&lt; "Unable to open file";
 }
 return EXIT_SUCCESS;

}//main
</code></pre>
