write a line at the top of a reversed data file with C++

Dears, I have written the following code to reverse a data file with deleting 15 lines from the top and the bottom. My question is: after reversing, how to write a certain line at the top of the reversed file, say" The reversed file is:"

Thanks in advance.

[code]
Put the code you need help with here.
#include <stdio.h>
#include <stdlib.h>
#include <fstream>
#include <iostream>
#include <string>
#include <stack>
#include"stdafx.h"
using namespace std;
int main () {
string s;
ifstream in;
in.open("input.txt");

ofstream outfile;
outfile.open("out.txt");

stack<string> lines;
string temp;
while(getline(in, temp))

lines.push(temp);
while(!lines.empty())
{

for(size_t i = 0; i < 17; ++i) {

lines.pop();

}

while(lines.size() > 17) {
outfile << lines.top() << endl,
lines.pop();
}

}

in.close();
outfile.close();

return 0;
}
Please complete the code tag with a [/code]
after reversing, how to write a certain line at the top of the reversed file

Change the sequence of events so that line gets written to the file before, not after. Do that first, not last.
Topic archived. No new replies allowed.