I am having a hard time with an assignment, I am given a .txt file with data in the following format:
Michael Schumacher
Allemagne; 250 91
1994 1995 2000 2001 2002 2003 2004
Benetton; Ferrari;
Fernando Alonso
Espagne; 132 21
etc...
I need to read this file and funnel the data in appropriate variables:
full name ----> to string
country; numberOfRace numberOfVictories ----> to string; to int, to int
all years separated by spaces ----> to an array
Sponsor1; [Sponsor2(optional)]; ----> to an array
full name2.....
I have spent 3 days trying to assign the data properly with a mixture of getlines and file >> and can't manage to get the array right, here my most recent attempt:
for (int i = 0; i < NPILOTES; i++) {
getline(fichier, liste.pilotes[i].nom);
getline(fichier, liste.pilotes[i].pays, ';');
fichier >> liste.pilotes[i].nCourses;
fichier >> liste.pilotes[i].nVictoires;
fichier.ignore();
// liste des annees
string line;
getline(fichier, line);
int position = 0, compteur = 0;
while ((position + 4) > line.length()) { // doesn't work, nothing gets in the array
line.substr(position, 4) =
liste.pilotes[i].annees.liste[compteur];
position += 5;
compteur++;
}
liste.pilotes[i].annees.n = compteur;
// liste des constructeurs automobiles
getline(fichier, line);
//????
}
variable names are in french as required by my class but it shouldn't be too hard to understand(pays = country, annees = years, constructeur = sponsor). Please keep in mind it's a first year programming class, so I am not allowed to use advanced concept like objects and vectors...
Thanks in advance for your input