If I input first name-last name how can I make the output last name-first name?

I want to change the input around, how can I pull off something like this? I really need help.

For example if I input Bob Joe

I would want the output to be Joe Bob
Use one variable for the first name and one for the last name. Then output the last name first then first name.
Bob Joe will be a single character string.
http://www.cplusplus.com/reference/string/string/
There are a few member functions that will help you there. Good luck!
This type of logic can work.

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
28
29
30
31
32
33
34
35
36
37
#include <iostream>
#include<cctype>

using std::cout;
using std::cin; using std::string;

int main()
{


string name;
getline(cin, name);
string first_name(name.size(), ' ');

//to get the first name
for (string::size_type i=0; i!=name.size(); ++i)
{
    if (isspace(name[i])) //will check if "i" char of name is space, if yes then break and out of the loop.
    break;
    first_name[i]= name[i];

}
int ch_cnt=0;
//to get the no. of char in first name
for (string::size_type i=0; i!=first_name.size(); ++i)
{
if (isalnum(first_name[i]))
 ++ch_cnt;

}

first_name.erase(ch_cnt, first_name.size()); // remove the unnecessary spaces form first name

cout <<first_name <<" " << "How are you?";

return 0;
}


So we can get last name also in a string and print it.
Topic archived. No new replies allowed.