I am trying to read two strings from the users and output them. If I type in "Micheal Jordan" for the first input, the program won't give me a chance to enter my second string.
#include "iostream"
#include "cstring"
int main()
{
using namespace std;
string name;
string dessert;
cout << "Enter your name: \n";
cin >> name;
cout << "Enter your favorite dessert: \n";
cin >> dessert;
cout << "I have some delicious " << dessert << " for you, " << name << "." << endl;
return 0;
}
output:
./a.out
Enter your name:
Micheal Jordan
Enter your favorite dessert:
I have some delicious Jordan for you, Micheal.
The code works fine if I input a name without a space.
./a.out
Enter your name:
MichealJordan
Enter your favorite dessert:
Cake
I have some delicious Cake for you, MichealJordan.
So I am guessing it's the space that creates this problem, can you guys tell me how to fix it? And I am also wondering what's going on with the space. Thank you!