I have a txt file that looks like this:
Student ID:97707; Grades: 87.73, 90.41, 91.74, 95.04, 99.13; Name:Davis, Artur
Student ID:23628; Grades: 58.09, 65.18, 68.62, 68.62, 98.05; Name:Davis, Susan
Student ID:49024; Grades: 18.37, 66.06, 68.07, 80.91, 96.47; Name:DeGette, Diana
I need to read the id, grades and names;
The id to a separate array
the grades to a 2-d array
and the names to a c style string.
Where do I start, im having trouble read the dummy to start
Can you help me start?
Thanks!
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 39 40 41 42 43 44 45 46 47 48
|
int main()
{
char filename[15] = "ex.txt";
string names[MAX_NAMES];
double grades[MAX_ROWS][MAX_COLS];
int id[MAX_IDS];
int index = 0;
ifstream fin;
int idnumbers;
double grade;
int ids;
char dummy[1000];
fin.open( filename );
if( !fin.good() )
{
cout << "File cannot be found!" << endl;
}
fin >> dummy;
fin >> idnumbers;
fin >> dummy;
fin >> grade;
fin >> dummy;
while( fin.good() )
{
cout << ids<< " "; //doesn't display anything
cout << grade << " "; //doesn't display anything
fin >> dummy;
fin >> idnumbers;
fin >> dummy;
fin >> grade;
fin >> dummy;
}
system("pause");
return 0;
}
|