In line 12 of your first code snippet you declare a global variable "multi" of class player. Then the function multi_data is kinda correctly filling a vector "players", but I'll come back to that later.
In function multi_fight you all read the players' names into that global object multi. As the vector players containes
copies of that global object, the players' names in the vector are not modified. Then, line 34 shouldn't compile at all because variable "multi" is not an array. I assume you meant to write
players[i].name
.
Anyway, you don't need the variable multi at all. Just remove it from your code:
1 2 3 4 5 6 7 8 9 10 11 12
|
class fighter
{
public:
string name;
int stamina;
bool alive;
fighter()
{
stamina=0;
alive=true;
}
}; // here
|
To add empty players into vector, replace your line 23 to:
players.push_back(player()); // a nameless object of class player is created and added to the vector
Finally read into the variables stored in the vector, and use them for output:
1 2 3
|
cout<<"Please enter in the names of the players"<<endl;
cin>>players[i].name; // here
cout<<players[i].name<<endl; // and here
|
Same goes for line 40. Good luck!