【发布时间】:2018-03-17 09:38:17
【问题描述】:
//class
class student
{
public:
int rno;
string name;
int marks;
int ran;
void getinfo()
{ a:
cout<<"\t \tenter the roll number"<<endl;
cin>>rno;
cout<<"\t \tenter the name"<<endl;
getline(cin,name);
cout<<"\t \tenter the marks"<<endl;
cin>>marks;
}
void showinfo()
{
cout<<"\t"<<ran<<"\t "<<rno<<" \t\t"<<name<<" \t\t"<<marks<<endl<<endl;
}
};
当我在为 roll no 提供输入后在控制台中获取对象的输入时,它正在打印“输入名称”,然后没有任何机会提供输入,它正在显示下一个打印语句,即“输入分数”。 getline 语句没有从控制台获取输入有什么原因吗??
【问题讨论】:
-
使用
cin.ignore()
标签: c++ string class io getline