cin - C++ not taking all inputs -
i creating simple c++ program. users input string .my program running fine when enter name space console skip next input here code.
#include <iostream> using namespace std; // program can see cout , 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(); }
it not skipping, stops reading after encountering space.
use std::getline(std::cin, name);
Comments
Post a Comment