您的位置:首页 > 编程语言 > C语言/C++

C++ 的 getline 函数时遇到的问题

2020-02-15 08:28 716 查看

程序代码:

#include <iostream>
#include <string>
using std::cout;
using std::cin;
using std::endl;
using std::string;
class Human
{
public:
void GetName()
{
cout<<"请输入名字:";
std::getline(std::cin, thename);
}
void GetStature()
{
cout<<"请输入身高(厘米):";
cin>>stature;
}
void GetWeight()
{
cout<<"请输入体重(公斤):";
cin>>weight;
}
void PrintStature(){cout<<"身高为:"<<stature<<"厘米"<<endl;}
void PrintWeight(){cout<<"体重为:"<<weight<<"公斤"<<endl;}
void PrintName(){cout<<"姓名为:"<<thename<<endl;}
private:
string thename;
int stature;
int weight;
};
int main()
{
char GoOn='y';
Human *Xman=new Human;//定义指针对象
while(GoOn=='y')
{
Xman->GetName();
Xman->GetStature();
Xman->GetWeight();
Xman->PrintName();
Xman->PrintStature();
Xman->PrintWeight();
cout<<"是否继续输入?(y/n)";
cin>>GoOn;
if(GoOn=='n'){break;}
}
delete Xman;
return 0;
}


  • 点赞
  • 收藏
  • 分享
  • 文章举报
ai13927511595 发布了33 篇原创文章 · 获赞 0 · 访问量 2010 私信 关注
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: