Strings are your friends.

I'm doing the strings are your friends exercise on this page. http://www.cplusplus.com/forum/articles/12974/
Is there a way to put a space between the user first and last name when the program outputs string fullname without the user having to put a space after they enter their first name. Here is my code.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
#include <string>
using namespace std;

int main(){
    int d;
    string first, last, fullname;
    cout<<"Enter your first name: ";
    getline(cin,first);'\n';
    cout<<"Enter you last name: ";
    getline(cin,last);'\n';
    fullname=first+last;
    cout<<"Your full name is "<<fullname;
}
fullname=first+" "+last;
Also, what are those
'\n';
supposed to do? It's a no-op.
Just in case my explanation wasn't clear enough.

Ex:If the user enters Mike for string first and Jordan for string last.
The program will output "Your full name is MikeJordan."

I don't know how to get the program to put a space between the user first and last name without having the user manually put a space after they enter their first name.
I showed you how, so what's the problem now?
Sorry I wrote that post before I saw yours.
I realized I didn't need '\n';. Thanks for the help. Here is my code now.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
#include <string>
using namespace std;

int main(){
    int d;
    string first, last, fullname;
    cout<<"Enter your first name: ";
    getline(cin,first);
    cout<<"Enter you last name: ";
    getline(cin,last);
    fullname=first+" "+last;
    cout<<"Your full name is "<<fullname;
}
Topic archived. No new replies allowed.