I wrote some code in order to double space a file in C++, currently the program takes in one file and returns a different file, that is double spaced. I want the program to return the same file to the file directory. I'm pretty at this point I need to a use a temporary file, which is fine, but I would like to at the end of the program eventually return the same file(but double spaced to the user). Any help would be appreciated. Here is my code thus far.
#include <fstream>
#include <iostream>
#include <cstdlib>
using namespace std;
int main( )
{
ifstream fin;
ofstream fout;
fin.open("story.txt");
if (fin.fail( ))
{
cout << "Input file opening failed.\n";
exit(1);
}
fout.open("numstory.txt");
if (fout.fail( ))
{
cout << "Output file opening failed.\n";
exit(1);
}
char next;
int n = 1;
fin.get(next);
fout << n << " ";
while (! fin.eof( ))
{
fout << next;
if (next == '\n')
{
fout << endl;
}
fin.get(next);
}
fin.close( );
fout.close( );
return 0;
}