Detecting ENTER key in C++

前端 未结 7 749
不知归路
不知归路 2020-12-17 03:07

I have a program like this,

char name[100];
char age[12];
cout << \"Enter Name: \";
cin >> name;

cout << \"Enter Age: \";
cin >> age         


        
7条回答
  •  死守一世寂寞
    2020-12-17 03:40

    When you use cin.get() compiler will take the lastly used Enter(i.e Enter key pressed while entering name). so you need to make the compiler to avoid the lastly entered Enter key to do so you need to include cin.ignore() before using cin.get().

提交回复
热议问题