Formatting To Output File

Apr 19, 2012 at 2:22pm

Trying to figure out when the program is run more than once how to make it so that in outputfn function that the formatting only copies to output file once but variable information keeps copying with every new students information.

*there are other functions everything else works fine



void outputfn(string fname, string lname, float total, float progavg, float testavg,
float courseavg, string letter){



cout<<fixed<<showpoint<<setprecision(2)<<left;


cout<<"\n1234567890123456789012345678901234567890123456789012345678901234567890"<<endl;
cout<<setfill('=')<<setw(70)<<""<<setfill(' ')<<endl;

cout<<setw(20)<<"Student Name"
<<setw(10)<<"Total"
<<setw(10)<<"Program"
<<setw(10)<<"Test"
<<setw(10)<<"Course"
<<setw(10)<<"Grade"<<endl;

cout<<setw(20)<<" "
<<setw(10)<<"Points"
<<setw(10)<<"Average"
<<setw(10)<<"Average"
<<setw(10)<<"Average"<<endl;

cout<<setfill('-')<<setw(70)<<""<<setfill(' ')<<endl;

cout<<setw(20)<<fname+" "+lname
<<setw(10)<<total
<<setw(10)<<progavg
<<setw(10)<<testavg
<<setw(10)<<courseavg
<<setw(10)<<letter<<endl;

cout<<setfill('=')<<setw(70)<<""<<setfill(' ')<<endl;

cout<<fixed<<showpoint<<setprecision(2)<<left;


fout<<"\n1234567890123456789012345678901234567890123456789012345678901234567890"<<endl;
fout<<setfill('=')<<setw(70)<<""<<setfill(' ')<<endl;

fout<<setw(20)<<"\n\nStudent Name"
<<setw(10)<<"Total"
<<setw(10)<<"Program"
<<setw(10)<<"Test"
<<setw(10)<<"Course"
<<setw(10)<<"Grade"<<endl;

fout<<setw(20)<<" "
<<setw(10)<<"Points"
<<setw(10)<<"Average"
<<setw(10)<<"Average"
<<setw(10)<<"Average"<<endl;

fout<<setfill('-')<<setw(70)<<""<<setfill(' ')<<endl;



fout<<setw(20)<<fname+" "+lname
<<setw(10)<<total
<<setw(10)<<progavg
<<setw(10)<<testavg
<<setw(10)<<courseavg
<<setw(10)<<letter<<endl;


fout<<setfill('=')<<setw(70)<<""<<setfill(' ')<<endl;



}

Apr 19, 2012 at 8:52pm
If I understand your question, you need to add ios::app after you declare your ofstream. Example:

ofstream fout("file.txt", ios::app);
Apr 19, 2012 at 9:01pm
This is a beginner course we haven't touch ios::app yet. I have ofstream declared globally, per professor, I'm running this program on a loop from main of about 6 functions. I need my output function to output the formatting such as "Name", "Scores", all that stuff and then create a list underneath of all the input from consecutive loops.
Topic archived. No new replies allowed.