I know but I am confused how to create two separate variables ?
I started c++ two days ago and I am learning it in english which is my 2nd language since I'm an international student in the states....it will take some time till everything will make sense.
Two variables ?
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string mystr1;
string mystr2;
cout << "What's your first name? ";
getline (cin, mystr1);
cout << "What is your last name";
getline (cin, mystr2);
A variable is like a cup. You can fill it with water, but if you were to want to put coca-cola in the cup, you'd first need to empty the water.
Originally, you were using one variable: string mystr;
Then you called getline() to fill your variable with some data (filling the cup with water)
you then called getline() again to fill your variable with different data (emptying the water and putting in coca-cola)
When you tried to output the first and last names with that string, all you were getting was the last name, because you had over-written the first.
The solution being to declare two string variables, each for their own purpose. - two cups, one for water, one for coca-cola.
Hoped that helped you understand.
EDIT:
Didn't see your post.
To put space in between them, simply manipulate your cout call.
Since it appears you know you can add numerous "<<" operators, try putting something between mystr1, and mystr2.