***Newbie*** Need help with strings

Please help me with the following code. I need to return both first and last name respectively using the string class. The code below only return the last name. Need to return both first and last name. The output only returns "Johnson".

#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

class statusName
{
public:
statusName ();
statusName(string &first, string &last);
~statusName ();

void setName(string &fn, string &ln);
string getName();
void print();

private:
string firstname;
string lastname;
};

statusName ::statusName (string &m, string &n)
{
//setName(m, n);
firstname = m;
lastname = n;
}

statusName ::~statusName ()
{
}

void statusName::setName(string &o, string &p)
{
firstname = o;
lastname = p;
}

string statusName::getName()
{
return(firstname, lastname);
}

void statusName::print()
{
cout <<"What is your name " << getName();
cout << endl;
}

int main()
{
string x = "Mike";
string y = "Johnson";
statusName myname(x, y);

myname.print();

return 0;
}
closed account (E0p9LyTq)
Your class getName() function was in error if you are wanting to return both first and last names:

1
2
3
4
string statusName::getName()
{
   return firstname + " " + lastname;
}
closed account (E0p9LyTq)
And PLEASE learn to use code tags, it makes reading your source much easier.

http://www.cplusplus.com/articles/jEywvCM9/
Thank you so much FurryGuy. I really appreciate your help.
Topic archived. No new replies allowed.