I need to be able to use a private class variable in several cout statements. I need to do something like this..
Code:
cout <<"Hello " <<Person.displayName() <<"how are you today" <<endl;
but that obviously gives me errors.
Here is the class, the code isn't perfect and I actually typed it out in wordpad. None of it has been compiled so please disreguard all the obvious errors.
Code:
class Persons {
public:
void setName(string);
string getName();
void displayName();
private:
string PersonName;
};
void Person::setName(string name){
PersonName = Name;
}
string Person::getPName() {
return PersonName;
}
void Person::displayPName() {
cout <<getName();
}
Now, I can use it the way I want but I have to do it in a rather messy way.
Code:
cout <<"Hello ";
Person.displayName();
cout <<" how are you today?" <<endl;
Is there a better way to do this so I don't have to break up the cout statments?