1

my problem is when I run this code it skips the line of getline(cin,emp_name) for some reason and print nothing in showdata(). but it works for the emp_job aren't they the same thing? thank you in advance.

     #include <iostream>
        #include <string>
        using namespace std;
        class emp {
        private:
            long int emp_number;
            string emp_name;
            string emp_job;
            float emp_bonus;
        public:
            void getdata() {
                cout << " enter your id ";
                cin >> emp_number;
                cout << " enter your name ";
                getline(cin , emp_name);
                cout << " enter your job tital " ;
                getline(cin , emp_job);
            }
            void showdata() {
                cout << " you id is " << emp_number << endl;
                cout << " your name is " << emp_name << endl;
                cout << " your job is " << emp_job << endl;
            }
        
        
        };
        
        
        
    
    
    
        
        int main() {
        
            emp one;
            one.getdata();
            one.showdata();
        
            return 0;
        }
mo7amed
  • 41
  • 4
  • Duplicate of [Why does `std::getline()` skip input after a formatted extraction?](https://stackoverflow.com/questions/21567291/why-does-stdgetline-skip-input-after-a-formatted-extraction) – WhozCraig Mar 12 '21 at 15:44

0 Answers0