char combining

I am wanting to combine two variables that are used seperate. I know I will need both as seperate, but is there a way to combine them for when I will use both? For example: firstName and lastName used seperate to differentiate between different family members but wholeName to make cout and other functions specific to that person? I tryed this:

char fName[25],lName[25];
string name=(fName[25])(lName[25]);

I hope I am communicating what I need well enough.
use strings for fName and lName

Then if you only plan to combine them for cout just do this at the time of cout

cout << fName << " " << lName;

Or if you need them combined for comparison or anything
string Name = fName + " " + lName; // I'm pretty sure that will work as advertised.

Edit: corrected typo
Last edited on
I'm pretty sure you can only use one + with string...so you would have to do this:

1
2
string Name = fName + " ";
Name.append(lName);
ok.. i wasn't sure if you could use multiple +'s..

But then you could always use
string Name;
Name += fName;
Name += " ";
Name += lName;
You can use multiple +'s with string, see http://www.cplusplus.com/reference/string/operator+.html
Topic archived. No new replies allowed.