I'm trying to write a program for a class where players participate in a rock paper scissors tournament. I'm currently working on option 2 which is supposed to add a player to the vector of players, but it's showing me an error on line 54. It appears under the .pushback part: error C2039: 'pushback' : is not a member of 'std::vector<_Ty>'.
I'm not sure why this is happening. .pushback should be a member of all vectors, right?
#include <iostream>
#include "people.h"
#include <vector>
#include <string>
usingnamespace std;
void printplayers(vector<People> players)
{
for (int i=0; i<players.size(); i++)
{
string name=players[i].getName();
int wins=players[i].getwins();
int losses=players[i].getlosses();
int draws=players[i].getdraws();
double winpercent= players[i].getwinpercent();
cout<<name<<" Wins:"<<wins<<" Losses:"<<losses<<" Draws:"<<" Percent of wins:"<<endl<<endl;
}
}
int main()
{
int bob=0;
while (bob==0)
{
cout<<"Welcome to the Arena! Please select an option!"<<endl;
cout<<"(1) Show players"<<endl;
cout<<"(2) Add a new player"<<endl;
cout<<"(3) Add an existing player to the line-up"<<endl;
cout<<"(4) Show the line-up"<<endl;
cout<<"(5) FIGHT!"<<endl;
cout<<"(0) Quit"<<endl;
vector<People> players;
int menuchoice;
cin>>menuchoice;
if (menuchoice==1)
{
cout<<"Your players:"<<endl;
printplayers(players);
}
if (menuchoice==2)
{
cout<<"Please enter player name."<<endl;
string playername;
cin>>playername;
People*enterthearea=new People(playername, 0, 0, 0, 0);
players.pushback(enterthearena);
}
if (menuchoice==3)
{
}
if (menuchoice==4)
{
}
if (menuchoice==5)
{
}
if (menuchoice==0)
{
return 0;
}
}
}
It may sound trite, but one of the hardest things about programming is believing what the compiler tells you. If it says that a function doesn't exist then you need to check your spelling very carefully. If that looks okay then check the class definition to see if you've got the name right. Don't rely on memory.
I can't tell you how many times I've seen people waste hours because they think "I know this part is okay so I won't look there" when in fact, that part is where the problem lies.