glibc and seg fault error

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.


Thanks in advance


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
49
50
51
52
53
54
55
56
57
58
59
60
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;
            }
         }
      }

   }
}
I don't see anything out of the ordinary here. Post your code for Player.
Topic archived. No new replies allowed.