I'm reading from a file into an array of objects i created called Team. The file is written in this format:
Shane Vitorino
CF
8
8
H
H
H
B
B
O
O
K
Ben Francisco
.......
The first line is the player's name, the second line is his position, the third is his number, the fourth is how many swings, and the rest are what those swings were and so forth for 16 total players. Here is my read function:
void readRoster(player rrTeam[], int count)
{
ifstream fp;
fp.open("player.dat");
cout << endl << "Values are being read from file..." << endl;
for (int i = 0; i < count; i++)
{
string pn;
string pos;
int num;
int numatBats = 0;
int numbaseOnBalls = 0;
int numstrikeOuts = 0;
int numHits = 0;
getline(fp, pn);
rrTeam[i].setPlayerName(pn);
fp >> pos;
rrTeam[i].setPosition(pos);
fp >> num;
rrTeam[i].setNumber(num);
fp >> numatBats;
rrTeam[i].setatBats(numatBats);
for (int j = 0; j < numatBats; j++)
{
char temp;
fp >> temp;
if (temp == 'H')
numHits++;
else if(temp == 'K')
numstrikeOuts++;
else if(temp == 'B')
numbaseOnBalls++;
}
rrTeam[i].setHits(numHits);
rrTeam[i].setStrikeOuts(numstrikeOuts);
rrTeam[i].setBaseOnBalls(numbaseOnBalls);
}
fp.close();
}
The 'idea' behind my loop is that it was supposed to read the player's information and record it up to the number of 'atBats', then count the hits, etc. of that player based on the number of atBats (via the second loop), record that, then start over again but for the next player (I.E rrTeam[1]) until it hits 15!
The code I have written gets ALL of the first player's information correctly (including the hits, etc.), but records nothing starting at the second player's name. Any help would be MASSIVELY appreciated! If I need any additional information to provide please let me know!