Entering name with space

I need to make my code shorter. In a way that, if a user is asked what his/her name is, they only need to input one line and the program will reply with the whole input

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <string>

using namespace std;

int main ()
{
	string x;

	cout << "What is your name?";
	cin>>x;
	cout <<"Hello, "<<x;




  system("pause");
  return 0;
}


so far in my code, only the first name is displayed. Any ideas guys? Thanks in advance!
closed account (oy0Gy60M)
cin >> x; only accepts a word. If you want to accept a whole string, use getline.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
#include <string>

using namespace std;

int main ()
{
	string x;

	cout << "What is your name?";
	getline(cin, x);
	cout <<"Hello, "<<x;

  system("pause");
  return 0;
}
Last edited on
Awesome! Thanks man! God Bless!
Topic archived. No new replies allowed.