reading from a file into an array

Teacher has supplied a txt file from which we're supposed to get the information. I've looked in my text book for examples, but those are user-input based. Here's what I have so far:

#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;

int main ()
{
const int STUDENTS = 25;
const int NAMES= 80;
const int TESTS = 4;
string studentNames [STUDENTS][NAMES];
double gradeBook [STUDENTS] [TESTS];
int S = 0; //number of students
int T; //number of tests
int N = 0; //number of entries
ifstream inFile ("classData.txt");

inFile.open("classData.txt");
cout << "nNow reading 'classData.txt'...";

//TO READ THE NAMES OF A MAXIMUM OF 25
//STUDENTS AND THEIR FOUR PERCENTAGES
//FROM A FILE
while (S<STUDENTS)
{
for (T=0; T<4; T++)
{
inFile >> gradeBook [S][T];
}

inFile >> studentNames [S][NAMES];

if (! inFile.eof())
{return 0;}
S+=1;
}


any help would be great...thanks.
Parsing data files is largley dependent on the format of the data within the file. Could you copy paste the text file into your next post?

EDIT: Also I believe you're missing a close bracket '}' intended for your "while(...)" loop.
Last edited on
Topic archived. No new replies allowed.