0

I am creating a simple c++ program. To get Users input as string .My program is running fine but when i enter name with space console skip the next input here is my code.

#include <iostream>

using namespace std; // So the program can see cout and endl

class Etradehouse
{  
 private:
    string cnic,name,fname, dob,qua, des,join_date , number , address;
    int sal;    
 public:
     void getData(){ 
   cout<<"\nPlease enter National identity Card number : \n";
    cin >>cnic ; 
   cout<<"Please enter name: \n";
   cin >> name; 
   cout<<"Please enter father name : \n";
   cin >> fname; 
   cout<<"Please enter Date of birth : \n";
   cin >> dob; 
   cout<<"Please enter qualification : \n";
   cin >> qua; 
   cout<<"Please enter designation : \n";
   cin >> des; 
  }
}; // Class ends here

int main()
{
 Etradehouse obj;
  obj.getData();  

}
Klaus
  • 538
  • 8
  • 26
Zainab Zainab
  • 80
  • 1
  • 10

1 Answers1

1

It is not skipping, it just stops reading after encountering a space.

Use std::getline(std::cin, name);

Nishant
  • 1,635
  • 1
  • 11
  • 24