C++:跳过第一个用户输入提示
C++ : First User Input Prompt Is Skipped
请问我的代码需要帮助吗?它用于 class Animal ,用户在其中输入一组 body 部分的描述。
我相信我已经正确地初始化了数据成员和 class 方法。
在 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();
}
当我 运行 它跳过 "Which animal are you" prompt.I 不知道,我想我错过了一些东西,这就是它被跳过的原因
感谢您的帮助
该行的 cout 后缺少左尖括号。
请问我的代码需要帮助吗?它用于 class Animal ,用户在其中输入一组 body 部分的描述。
我相信我已经正确地初始化了数据成员和 class 方法。
在 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();
}
当我 运行 它跳过 "Which animal are you" prompt.I 不知道,我想我错过了一些东西,这就是它被跳过的原因
感谢您的帮助
该行的 cout 后缺少左尖括号。