no match for 'operator<<' in 'std::cout << (&it)->_

Pages: 12
Remove line 24 from player.h

What are you doing is creating another vector with the same name as member, shadowing it. All changes are made to the local vector and do not persist.

This actually should give a warning. If you do not have warnings enabled in your IDE, do it. They help greatly. If they are enabled, read them.

Later you will probably want to separate saving another player in database and printing content of database, so you won't have to add another player if you just want to print all players in database.


@Dput You do see, that he had multiple problem with print function, right? Multiple responsibility, taking unnesesary parameters, doing unneeded work. Why not to show how it should be done instead of dirty patching existing code full of bad habits? Especially if it takes almost no work? (I did sugest to replace gotos but did not insist on it because it will truly lead to complete rewrite)
Last edited on
do you mean line 24 from database.h
Yes, sorry. database.h

Later you will probably want to separate saving another player in database and printing content of database, so you won't have to add another player if you just want to print all players in database.


by simple language please
Last edited on
closed account (j3Rz8vqX)
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
class database
{
    private:
    player get_datam;
    vector<player> playersave;

    public:
    void save (player);
    void display ();
};

void database::save(player get_datam)
{
    cout<<"vector"<<endl;

    playersave.push_back(get_datam);
}
void database::display()
{
    vector<player>::iterator it = playersave.begin();
    for( it = playersave.begin(); it != playersave.end(); ++it )
    {
        it -> print();
    }
}

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
137
int main()
{
    string a;
int exit;
string letter;
int i = 1;
int n_l=0, n_r=0, n_e=0;
string line;
    string firstname;
    string lastname;
    string email_;
    string age_;
    string gender_;
    string optionn;
    player get_datam;
    database savem;



    //***the main question***//
    thestart:
    cout<< "1-Add a player" << endl;    // program's question
    cout<< "2-list players" << endl;
    cout<< "3-play game" << endl;
    cout<< "Q-Quit" << endl;
    cin >> optionn;

option:
if (optionn== "1")  // if the variable equation equals 1
{

goto addplayer ;    // going to the option 1 add aplayer
}

else if (optionn== "2")    // going to the option 2 list player
{
goto listplayer ;
}

else if (optionn== "3")    // going to the option 3 playgame
{
goto playgame;
}


else if (optionn== "q")    // exit
{
goto end;
}


else
{
cout <<"Error:Invalid option."<<endl;
goto thestart;    //going to the beginning and repeating all the previous steps
}



//*** option one***//
{
addplayer: // lable of goto command

get_datam.get_data();
savem.save(get_datam);//<---SAVE your player!
//***** player information ***//
//*** connect to the class that deal with player's information ***//
 get_datam.print();
  goto thestart;
}
//**************************//


//****option two***//

//*** list all plyers who has been saved in the text file listplayers ***//
{listplayer:


  savem.display();//<---Print your player!
 goto thestart;
//**************************//


}
//*** option three ***//
//*** program game ***//

{
playgame:
cout<<i<< ".Enter a letter if Left or Right is greater/equal: L  E  R" << endl;    // program's question
cout<< "Q:Quit" << endl;
cin >> letter;


if (letter=="l"||letter=="L"||letter=="r"||letter=="R"||letter=="e"||letter=="E")
{
cout<< "Answer:"<<letter<< endl;
i = i + 1 ;    // changing the number of the question to the next number
if (letter=="l"||letter=="L")   //counting how many the letter l has been entered
{
n_l = n_l + 1;
}

else if (letter=="r"||letter=="R")   //counting how many the letter r has been entered
{
n_r = n_r+1 ;
}

else   //counting how many the letter e has been entered
{
n_e = n_e + 1 ;
}
goto playgame ;    // going to the playgame and repeating all the previous steps
}

else if (letter=="q"||letter=="Q")    // print the result and exit from the program
{
i = i-1 ;    // uncounting the the question if the answer is q
cout <<i<<"questions:    "<<n_l<<"L    "<<n_e<<"E    "<<n_r<<"R"<<endl;
cout << "Enter any thing to quit" << endl;
cout << "bye" << endl;
cin>> exit;
}

else
{
cout <<"Error:Invalid option. Select L-E-R"<<endl;
goto playgame;    //going to the beginning and repeating all the previous steps
}
}

//***********************//

end:
  return 0;
}
Last edited on
I get it. Thanks so much
Thanks again. You helped me very much.
I am so happy to be a member of such a website have a nice people like you.
Topic archived. No new replies allowed.
Pages: 12