Trying to write a simple get and set function
Aug 1, 2018 at 10:28pm UTC
Hi im a complete noob and im trying to write a simple get and set function for a class of strings. Can someone show me how to do it and i dont want to use a default constructor. Thanks.
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
#include<iostream>
#include<string>
using namespace std;
class addressBook
{
public :
string Getname() {return itsName;}
string Setname(string name) {name = itsName;}
private :
string itsName;
string itsStreetNumber;
string itsTown;
string itsCounty;
string itsPostcode;
};
int main()
{
string theSpare;
addressBook pageOne;
cout << "Enter the name.\n" ;
getline(cin,pageOne.Setname(theSpare));
cout << "The line entered was " << pageOne.Getname()<< endl;
Aug 1, 2018 at 10:46pm UTC
Why do you keep creating new topics for the same question?
Respond to the people who responded to your previous topics.
Don't be a dick.
Topic archived. No new replies allowed.