C++:跳过第一个用户输入提示

C++ : First User Input Prompt Is Skipped

本文关键字:用户 输入 提示 第一个 C++      更新时间:2023-10-16

我可以帮忙编写代码吗?它适用于动物类,用户在其中输入一定数量的身体部位的描述。 我相信我已经正确初始化了数据成员和类方法。 在 void create(( 方法中有一个提示,当我运行程序
时第一个提示没有出现,除了那个提示之外,它都在工作。

这是代码:

#include <iostream>
#include <string>
using namespace std;
class Animal{
char birth[20];
char legs[20];
char eyes[20];
char ears[20];
char mouth[20];
char nose[20];
public:
void create(){
cout<<"Describe your animal"<<endl;
cout<"Which animal are you?: ";
cin.getline(birth, 20);
cout<<"Could you describe your legs?: ";
cin.getline(legs, 20);
cout<<"How good are your eyes?: ";
cin.getline(eyes, 20);
cout<<"And your sense of hearing?: ";
cin.getline(ears, 20);
cout<<"Can i know what your mouth looks like?: ";
cin.getline(mouth, 20);
cout<<"Lastly I'd like to about your nose: ";
cin.getline(nose, 20);
cout<<endl;
cout<<"I am a "<<birth<<endl;
};
void move(){
cout<<"My legs are "<<legs<<endl;
};
void see(){
cout<<"My eyes are "<<eyes<<endl;
};
void hear();
void eat();
void smell();
};
void Animal::hear(){
cout<<"My hearing is "<<ears<<endl;
}
void Animal::eat(){
cout<<"My mouth is "<<mouth<<endl;
}
void Animal::smell(){
cout<<"My nose is "<<nose<<endl;
}
int main(){
cout<<"tDescribe Animal Chareteristics"<<endl<<endl;
Animal eagle;
eagle.create();
eagle.move();
eagle.hear();
eagle.eat();
eagle.smell();
}

当我运行时,它会跳过"你是哪种动物"提示。我不知道,我想我错过了一些东西,这就是为什么它被跳过的原因

谢谢你的帮助

该行的 cout 之后缺少左尖括号。