Please help, I thought the program save all data into struc
*ptrstudent.
however, when cout it only print the last piece of data.
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
using namespace std;
struct Record_info {
string name;
double midterm;
double quiz;
double final;
}student[50],*ptrstudent;
int main (void){
double grade;
ifstream in ("test2.txt");
string line,word;
while (getline(in,line)){
ptrstudent = student;
if (line.find("#")!=string::npos)continue ;
istringstream anyname(line);
anyname>>ptrstudent->name>>student->midterm>>student->quiz>>student->final;
ptrstudent++;
}
for (ptrstudent=student; ptrstudent->name[0];ptrstudent++){
cout << ptrstudent->name<<endl;
cout << ptrstudent->midterm<<endl;
cout << ptrstudent->quiz<<endl;
cout << ptrstudent->final<<endl;
}
return 0;
}
/////////// input file "test2.txt" ///////////////////////
##########3
##########3
Tony 90.0 -15.2 98.2
##########3
Michael 95.0 17.2 92.2
/////////////////////////////////////////////
//////////////// output from program /////////////
Michael
95.0
17.2
92.2
////////////////////// Want the output as follow /////////////
Tonny
90.0
-15.2
98.2
Michael
95.0
17.2
92.2