so i'm trying to read in from a file but having lots of trouble so far all i get are segmentation faults or jibberish numbers when outputting and i just need a little bit of direction on how to solve this problem. i'm reading i don't have much experience with reading arrays in from a file and stuff. heres what i have.
those are my structs and my prime read is
array size is initialized to 100 and i have error checking to make sure the file opens and the dat file is
thank you in advance
Code:
struct date
{
int day, month, year;
};
struct student
{
string firstName, lastName;
int hours;
double points;
date dob;
};
Code:
students>> listOfS[arraySize].lastName >> listOfS[arraySize].firstName >> listOfS[arraySize].hours >> listOfS[arraySize].points >> listOfS[arraySize].dob.day >> listOfS[arraySize].dob.month >> listOfS[arraySize].dob.year;
while(!students.eof())
{
arraySize++;
cout << listOfS[arraySize].lastName << listOfS[arraySize].firstName << listOfS[arraySize].hours << listOfS[arraySize].points << listOfS[arraySize].dob.day << listOfS[arraySize].dob.month << listOfS[arraySize].dob.year;
}
Code:
Jones Pete 30 78.0 1 11 1973 Brown Carl 64 198.4 6 7 1985 Smith Ann 37 118.4 9 2 1980 White Mary 54 143.1 3 17 1975 Black John 47 87.4 12 10 1981 Flyn Bee 58 145.0 8 15 1987 Sikes Bob 23 88.78 2 11 1983
Comment