Detecting ENTER key in C++

前端 未结 7 748
不知归路
不知归路 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:25

    You might want to cin into a char variable and then check if it the ENTER key, and if not, continue getting characters and turn them into an int (using character substraction and all that). It is not a very pretty solution but it is the first thing that came into my head.

提交回复
热议问题