Strings with spaces?

This is my program:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>

using namespace std;

int main()
{

      string name;
      
      cout << "Welcome, What is your name?" << endl;
      cin >> name;
      cout << name << endl;
    
}


When you enter strings with a space, it doesn't print out the part of the string after the space. Why? I'm pretty new to C++ and I can't figure this out.
Because >> stops at whitespace.

If you want the whole line, use getline:

1
2
//  cin >> name;  // bad
getline(cin,name);  // good 
Thanks so much!
Topic archived. No new replies allowed.