C++:跳过第一个用户输入提示
C++ : First User Input Prompt Is Skipped
我可以帮忙编写代码吗?它适用于动物类,用户在其中输入一定数量的身体部位的描述。 我相信我已经正确初始化了数据成员和类方法。 在 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 之后缺少左尖括号。
相关文章:
- C++如何通过用户输入删除列表元素
- 如何使用用户输入在C++中正确填充2D数组
- C++MySQL C api用户输入行
- 如何只允许用户输入正整数
- C++如何计算用户输入的数字中的偶数位数
- 通过for循环使用用户输入填充列表
- 在C++中,我如何接受不同于同一行的用户输入
- 如果用户输入无效,如何使用字符串变量-C++重复输入命令
- 显示基于用户输入的整数的字符
- 根据用户输入用字母填充矢量,并将"开始"和"结束"放在四肢
- 我试图制作一个程序,要求用户输入问题和答案,但程序循环不正确
- 打印时有二叉树问题.用户输入不打印任何内容
- C ++奇怪的数组由用户输入
- 如何允许大写和小写用户输入?
- C++读取用户输入而不按回车键(Mac OS X),与Turbo Pascal中的读取键相同
- 如何存储用户输入的所有数据,然后在他们想要查看所有数据时显示它们
- 如何使用用户输入变量制作二维数组?
- 用户输入字符串的文件附加问题..C++
- 遇到此问题时遇到困难:允许用户输入数组的值并使用 for,而循环也输出输入的最大数字
- 如何使用递归循环我的代码(当用户输入无效输入时,它会再次提示他们)?