//헤더파일
#ifndef _KGS_H_
#define _KGS_H_
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
#define MAX 50
using namespace std;
typedef struct
{
string name;
int score[3];
int sum;
double aver;
}Student;
#else
#endif
//메인
#include "Data.h"
int _tmain(int argc, _TCHAR* argv[])
{
char fn[]="kgs.txt";
Student mStudent[MAX];
fstream fp;
int i,len =0;
fp.open(fn,ios::in);
if (fp.fail())
{
return 0;
}
i =0;
while (!fp.eof())
{
fp>>mStudent[i].name>>mStudent[i].score[0]>>mStudent[i].score[1]>>mStudent[i].score[2];
i++;
}
len = i-1;
for (i = 0;i<len;i++)
{
mStudent[i].sum = mStudent[i].score[0]+mStudent[i].score[1]+mStudent[i].score[2];
mStudent[i].aver=mStudent[i].sum/3.0;
}
for (i=0;i<len;i++)
{
cout<<mStudent[i].name<<" "<<setw(3)<<mStudent[i].score[0];
cout<<setw(3)<<" "<<mStudent[i].score[1]<<" ";
cout<<setw(3)<<mStudent[i].score[2]<<" ";
cout<<mStudent[i].sum<<" "<<mStudent[i].aver<<endl;
}
fp.close();
return 0;
}
==>kgs.txt 파일 내용
박진영 98 78 22
김진영 98 78 44
김소월 98 78 33
이인엉 98 78 32
발진발 98 78 54
머하냐 98 78 44
하하하 98 78 22
히히히 98 78 23
허어엉 98 78 100
=====================================
출력결과