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
|
#include <iostream>
#include <fstream>
using namespace std;
struct studentInfo
{
char name[30];
int age;
float gpa;
char grade;
};
int main()
{
studentInfo s[4] = {{"Dan Jonson", 10, 1.10, 'A'},
{"Billy Bobson", 15, 2.20, 'B'},
{"Jim Carlton", 20, 3.30, 'C'},
{"Donnie Darko", 250, 4.00, 'D'}};
fstream fFile;
fFile.open("c:\\windows\\temp\\students.txt", ios::out);
if(!fFile)
cout << "ERROR";
for(int x=0; x<4; x++)
{
fFile.getline(s[x].name,30);
fFile >> s[x].age;
fFile >> s[x].gpa;
fFile >> s[x].grade;
fFile.ignore();
}
fFile.close();
return 0;
}
|