I have to get this program to read from a text file and write the data to another text file. The problem i'm having is the format. It's typing everything on one line

#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;

//reading data from a file
int main()
{
	const int size = 244;
	char numbers[size];
	int count;
	ifstream inputfile;
	ofstream outputfile;

	inputfile.open("grades.txt");

for (count = 0; count < size; count++)
inputfile >> numbers[count];

inputfile.close();

for (count = 0; count < size; count++)
{
cout << numbers[count];
}
//Writing data to a file

	 outputfile.open("report.txt");
outputfile <<  "*******************************************************************************************************************************************"<<endl;
outputfile <<  "--------------------------------------------Dr. David Smith, Associate Professor-----------------------------------------------------------"<<endl;
outputfile <<  "--------------------------------------------Blue Ridge Community College-------------------------------------------------------------------"<<endl;
outputfile <<  "*******************************************************************************************************************************************"<<endl;


	 for (count = 0; count < size; count++)
	outputfile <<numbers[count];
	 

	 outputfile.close();



	return 0;
}

Line 25 should be:

cout << numbers[count] << endl;

And line 37 should be:

outputfile << numbers[count] << endl;

Yes I understand, it's all on one line, that's why I said you have to put endl in your output to solve this.

Because that's the way you made it, you said cout << numbers[count]; without adding a space(" "), or ending the line(endl)

If your trying to implement copying files then you can do something like this.

int main(){
 ifstream inputFIle('input.txt');
 ofstream outputFile('out.txt');
 char ch;
 while( inputFile.get(ch)) outputFile.put(ch)
}
This article has been dead for over six months. Start a new discussion instead.