Vector of pointers to struct

hey guys, I'm having a little bit of trouble with my code. it is s'pose to read the names and stats of basketball players from a file and store it in an individual structure. I can get the data into the structure but I dunno how to pass it to a function and read the data from there.
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#include <cstdlib>
#include <vector>
#include <iostream>
#include <string>
#include <fstream>
#include <cassert>

using namespace std;

struct Player
{
    string first;
    string last;
    int num;
    int min;
    int fga;
    int fgm;
    int tpa;
    int tpm;
    int fta;
    int ftm;
    int off;
    int def;
    int stl;
    int blk;
    int ast;
    int to;
    int pf;
    double tpp;
    double fgp;
    double ftp;
    double pointsPer48;
    double offensiveRating;
    double defensiveRating;
    double mvpRating;
};

bool getPlayerStats(Player*);
void calcPercentages(Player*);
void findTopOffensivePlayer(vector<Player*>);
void findTopDefensivePlayer(vector<Player*>);
void findMostValuablePlayer(vector<Player*>);
void outputPlayers(vector<Player*>);
void deallocatePointers(vector<Player*>);

ifstream infile;

int main()
{
    vector <Player*> vStruct;
    Player* ps = new Player;
    while(getPlayerStats(ps))
    {
        vStruct.push_back(ps);
    }

    outputPlayers(vStruct);
}

bool getPlayerStats(Player* ps)
{
  if(!infile.is_open())
    {
        infile.open("lab3.dat");
    }

    infile >> ps->num;

    if(infile.eof())
    {
        infile.close();
        return false;
    } else
    {
        assert(!infile.fail());
    }

    infile >> ps->first;
    assert(!infile.fail());

    infile >> ps->last;
    assert(!infile.fail());

    infile >> ps->min;
    assert(!infile.fail());

    infile >> ps->fga;
    assert(!infile.fail());

    infile >> ps->fgm;
    assert(!infile.fail());

    infile >> ps->tpa;
    assert(!infile.fail());

    infile >> ps->tpm;
    assert(!infile.fail());

    infile >> ps->fta;
    assert(!infile.fail());

    infile >> ps->ftm;
    assert(!infile.fail());

    infile >> ps->off;
    assert(!infile.fail());

    infile >> ps->def;
    assert(!infile.fail());

    infile >> ps->stl;
    assert(!infile.fail());

    infile >> ps->blk;
    assert(!infile.fail());

    infile >> ps->ast;
    assert(!infile.fail());

    infile >> ps->to;
    assert(!infile.fail());

    infile >> ps->pf;

    assert(!infile.fail());

    return true;
}

void outputPlayers(vector<Player*> vStruct)
{
    for(int i = 0; i < vStruct.size(); i++)
    {
        cout << vStruct[i].first << " " << vStruct[i].last << endl;
    }
}


it gives me the errors:
main.cpp:134: error: request for member ‘first’ in ‘vStruct.std::vector<_Tp, _Alloc>::operator[] [with _Tp = Player*, _Alloc = std::allocator<Player*>](((long unsigned int)i))’, which is of non-class type ‘Player*’

main.cpp:134: error: request for member ‘last’ in ‘vStruct.std::vector<_Tp, _Alloc>::operator[] [with _Tp = Player*, _Alloc = std::allocator<Player*>](((long unsigned int)i))’, which is of non-class type ‘Player*’

Thanks for any help!
It says right in the error code
cout << vStruct[i].first << " " << vStruct[i].last << endl;
should be
cout << vStruct[i]->first << " " << vStruct[i]->last << endl;
Because you are passing "vStruct" as a pointer, the compiler has to be told to dereference the data.
How on earth do you expect to remember what those variables stand for?

You're going to put this project down for a month and when you come back to it you'll be totally confused. Not to mention the difficulties anyone else will have if they try to look at your code.

Pick more descriptive names.
Topic archived. No new replies allowed.