Hmm, actually that code is a bit off. You'll have to concatinate '\n' after each getline(), plus of course declare filesize as an int. ;)
To write the file, just use ofstream in a similar way as I used the ifstream but with the '<<' operator, just like you would with cout (fout << fullfile;)...