C++: Reading from file and delimeters?

I have a file that looks like:
Student ID:88152; Grades: 83.67, 92.45, 74.43, 97.95, 76.45; Name:Abercrombie, Neil
Student ID:92485; Grades: 77.65, 92.31, 60.47, 67.12, 99.64; Name:Aderholt, Robert
Student ID:10623; Grades: 37.95, 83.11, 64.46, 74.76, 95.30; Name:Alexander, Rodney
Student ID:76793; Grades: 53.13, 81.02, 83.71, 90.75, 88.92; Name:Baca, Joe

I need to read the id numbers into an array, the grades into a 2d array and the names into a 2d c-style string arrays.

But i'm having trouble getting past the delimiters

This is what i'm trying but it doesn't work

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
fin >> dummy;
fin >> id;
fin >> dummy;
fin >> grades;
fin >> dummy;
fin >> names

while ( fin.good() )
  {
    // put the id, grades and name to array
    fin >> dummy;
    fin >> id;
    fin >> dummy;
    fin >> grades;
    fin >> dummy;
    fin >> names
  }
sounds like a job for getline(fin, str, ';');
Last edited on
Topic archived. No new replies allowed.