So I need help creating a program that will open a file and read the data from the file into an array of structs and then calculate a variety of things like highest, lowest, ave
This should read all your data into the array, you'll want an incrementor to
ifstream inStream; inStream.open("scores.txt");
while (!inStream.eof())
{
inStream >> StudentData arr[SIZE];
};
inStream.close();
My suggestion:
StudentData
object from a stream.while
loop in main
. In each iteration of the loop, read a StudentData
std::istream& operator>>(std::istream& in, StudentData& st)
{
return (in >> st.studentID
>> st.first_name
>> st.last_name
>> st.exam1
>> st.exam2
>> st.exam3);
}
and in main
:
openInputFile(inFile, inFileName);
size_t numItems = 0;
while ( inFile >> arr[numItems] )
++numItems;
At the end of that, you would have successfully read numItems
items into arr
.