The comma after the last name is what makes it a bit more difficult. If there was no comma (just a space), you could just do:
Code:
cin >> lastName;
cin >> firstName;
cout << firstName << " " << lastName << endl;
If you must read it in with the comma coming after the last name, then you might have to use something like a delimiter. This will read all the characters until the delimiter is read in.
Code:
char lastName[256];
cin.getline (lastName,256, ',')
So, that should read all the characters into lastName until the comma is reached. I think the string method is something like:
Code:
string lastName;
getline (cin,lastName, ',');
Using a delimiter should work, although, there might be an easier method to implement. I'm sure another forum member will mention it if there is.