I'm new to C++ and pretty new to coding in general, I'm trying to make a simple text based RPG for a bit of fun. I've made a class player, and I'm trying to edit it so that the user edits the name of the playerName but I'm getting errors and I really don't know why.
My main method:
// Thomas' Game.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <string>
#include "Player.h"
#include <fstream>
#include <istream>
using namespace std;
int main()
{
Player player;
cout << "Hello traveller, could I ask you your name?";
cin >> player.setName;
cout << "Hello " << player.getName << endl;
return 0;
}
My player class: .h
#pragma once
#include <iostream>
#include <string>
using namespace std;
class Player
{
private:
string playerName = "";
string playerRace = "";
int playerAge = 0;
public:
void setName(std::string);
string getName();
void setRace(std::string);
string getRace();
void setAge(int);
int getAge();
};
.ccp
#include "stdafx.h"
#include "Player.h"
void Player::setName(std::string name)
{
playerName = name;
}
std::string Player::getName() {
return playerName;
}
void Player::setAge(int age)
{
playerAge = age;
}
int Player::getAge() {
return playerAge;
}
void Player::setRace(std::string race)
{
playerRace = race;
}
std::string Player::getRace() {
return playerRace;
}
Severity Code Description Project File Line Suppression State
Error C2679 binary '>>': no operator found which takes a right-hand operand of type 'overloaded-function' (or there is no acceptable conversion) Thomas' Game.cpp 18Severity Code Description Project File Line Suppression State
Error C3867 'Player::getName': non-standard syntax; use '&' to create a pointer to member Thomas' Game c:\users\thomas\source\repos\thomas' game\thomas' game\thomas' game.cpp 19
are the errors I'm currently getting