writing multiple lines on text file
I am trying to set up a program that writes multiple lines on to a text file that is created, however the script keeps writing in just one line.
here is my script
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
#include <iostream>
#include <fstream>
using namespace std;
struct Team {
string name[10];
int record[5];
int GFGA[5];
};
struct Folder{
Team club[10];
};
int main()
{
int n= 1;
Folder N;
string outputFilename;
ofstream outputFile;
N.club[0].record[0]=1;
N.club[0].record[1]=2;
N.club[0].record[2]=3;
N.club[0].record[3]=4;
N.club[0].record[4]=5;
N.club[0].name[0]="Team";
cout << "Output filename: ";
getline (cin, outputFilename);
outputFile.open(outputFilename.c_str(),ios::out | ios::binary);
outputFile <<" Team "<< "GP "<< " W "<<" L "<<" OT "<<" PTS "<< endl; // first attempt
outputFile<<"\nline\nline2"<<endl; // second attempt using \n
outputFile<<"sasas";
for (int j=0; j<n; j++){
outputFile <<N.club[j].name[0]<<N.club[j].record[0]<<" "<<N.club[j].record[1];
outputFile<<N.club[j].record[2]<<" "<<N.club[j].record[3];
outputFile<<N.club[j].record[4]<<endl;
}
outputFile.close();
cout << "Done!\n";
return 0;
}
|
It writes only to one line. Even though I used endl; and "\n"
so why wont it write to multiple lines when I make a file?
remove ios::binary
thanks peter87
you are spot on with that.
Topic archived. No new replies allowed.