how do string accept characters having spaces?

how do string accept characters having spaces? Or do you know other ways to accept spaces? Let's say for a name.

1
2
3
   string first;
   string middle;
   string last;


1
2
3
4
5
6
7
cout<<"\tEnter your name";
cout<<"\n\nFirst Name: ";
cin>>first;
cout<<"Middle Initial: ";
cin>>middle;
cout<<"Last Name: ";
cin>>last;


When I enter a name with spaces, the output will have an error, no longer accepting Middle Initial or Last Name.
Last edited on
Use std::getline function. For example

std::getline( std::cin, first );
Topic archived. No new replies allowed.