I keep running into problems with my program to evaluate baseball stats. When I try to INPUT filename I run into glibc and if run TEAM identifier then i get a segmentation fault. The glibc didn't start happening until I put in the PLayerData.clear() statement.
int main( )
{
vector<Player> PlayerData;
vector<Player>::iterator P;
string A, A1, A2, A3;
for(;;)
{
cout << "\nPlease enter a command ( 'HELP' for further instruction ): ";
getline(cin, A);
A1 = A.substr(0, 5);
A2 = A.substr(0, 4);
if ( A == "HELP" )
{
cout << "Enter 'INPUT filename' to recieve data from a file" << endl;
cout << "Enter 'TEAM identifier' to display all players on that team\n";
cout << "Enter 'REPORT n HITS' to display top n players in hits\n";
cout << "Enter 'REPORT n BATTING' to display top n";
cout << " players in batting average\n";
cout << "Enter 'REPORT n SLUGGING' to display top n";
cout <<" players in slugging percentage\n";
}
if ( A1 == "INPUT" )
{
try
{
Player One;
if( !PlayerData.empty()) PlayerData.clear();
string filename = A.substr(6);
ifstream IN( filename.c_str(), ios::in );
while ( IN >> One )
{
PlayerData.push_back(One);
}
IN.close();
}
catch(...)
{
cout << "Invalid input please try again." << endl;
}
}
if ( A2 == "TEAM" )
{
string TeamName = A.substr(5);
for( unsigned I=0; I < PlayerData.size(); I++ )
{
if( PlayerData[I].get_team() == TeamName )
{
cout << PlayerData[I] << endl;
}
}
}
}
}