Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie help with <IFSTREAM> and <OFSTREAM>

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I have data in notepad that looks exactly like this...

CPSC230 01
SPRING 01
6
able 90 90
baker 80 80
charlie 70 70
delta 60 60
fox 59 59
echo 0 0

The problem I"m having is reading in the data and outputting it. What I want the program to do is read in all the lines, but it needs to store the number on the third line (in this case the 6) because that is the number of students (so the number could be 10, 4, 1 etc...) As far as outputting It should output the thirst two lines regular, but then should output the last 6 lines (students and their grades) with the format

STUDENT:
MIDTERM:
FINAL:

the midterm being the first grade and the final being the second. If anyone can please help me figure out the code for this that would be greatly appreciated. Thanks
 

something like this will do it for you

ifstream in("input");
ofstream out("output");
char buffer[128];

in.getline(buffer,128);
out<<&quot;CLASS: &quot;<<buffer<<endl;
in.getline(buffer,128);
out<<&quot;DATE: &quot;<<buffer<<endl;
int x = 0, y = 0;
in>>x;

for(int i = 0;i<x;i++)
{
in>>buffer;
in>>x>>y;
out<<&quot;STUDENT: &quot;<<buffer<<endl;
out<<&quot;MIDTERM: &quot;<<x<<endl;
out<<&quot;FINAL: &quot;<<y<<endl;
}

(This assumes the same format each time)

Good Luck

Matt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top