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;
}

Recommended Answers

All 2 Replies

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.