如何解决在cpp中获取数据作为输入
我试图让用户输入数据,但是编译器跳过了cpp程序中的getline函数。可能是什么问题?这是代码。
#include <iostream>
using namespace std;
struct Customer{
char name[10];
char email[30];
int age ;
int idno;
string date;
};
int main()
{
Customer cust;
cout<<"Enter the name of the customer"<<endl;
cin>>cust.name;
cout<<"Enter the email of the customer"<<endl;
cin>>cust.email;
cout<<"Enter the age of the customer"<<endl;
cin>>cust.age;
cout<<"Enter the id number of the customer"<<endl;
cin>>cust.idno;
cout<<"Enter the date of birth of the customer"<<endl;
getline(cin,cust.date);
cout<<"The details of the customer are"<<endl;
cout<<"Name :"<<cust.name<<endl;
cout<<"Email :"<<cust.email<<endl;
cout<<"Age :"<<cust.age<<endl;
cout<<"Id number :"<<cust.idno<<endl;
cout<<"Date of birth :"<<cust.date<<endl;
return 0;
}
Here is the output of the program
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。