Hi everyone,

I have a simple problem related to string, but I did not notice before that we can't give space in string input. For exmaple in the following program, take name input from user. If user enter M John, it will skip the enter email input(and the program will be terminated).

My question is, why is this happening. And what is the solution of this problem. Because I want spaces in string input. Anyone please help. Thanks !

#include <iostream>
#include <string>

int main()

   string name;
   string email;

   cout <<"Enter name : "<<endl;
   cin >> name;
   cout <<"Enter email : "<<endl;
   cin >> email;

   cout <<"\n\nProgram terminated !"<<endl;

return 0;
This question has already been answered. Start a new discussion instead.