我可以请求我的代码帮助。它适用于Animal类,用户可以在其中输入一组身体部位的描述。 我相信,我已正确初始化了数据成员和类方法。 在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();
}
当我跑的时候会跳过“你是哪个动物”的提示。我不知道,我想我错过了什么,这就是为什么它会被跳过
感谢您的帮助
答案 0 :(得分:2)
该线路上的cout后,你的左尖括号丢失了。