【发布时间】:2016-01-24 16:52:34
【问题描述】:
当用户输入姓名和姓氏时,我需要使用 getline 来存储整行。当我运行程序时,它通过 getline(cin,st[i].name); 行我的意思是输入功能不起作用,它会跳过下一个用于“分数”的 cin。
struct Student {
string name;
int score;
char grade;
};
void main() {
int SIZE;
cout << " How many students are you going to add ? ";
cin >> SIZE;
Student* st = new Student[SIZE]; // user determines size of array.
int i;
for (i = 0; i < SIZE; i++)
{
if (st[i].name.empty()) // if array list of name is empty, take input.
{
cout << "name and surname : ";
//cin >> st[i].name;
getline(cin, st[i].name);
}
cout << "Score : ";
cin >> st[i].score; // take quiz score from user.
-- 我没有放整个 main 函数。
所以当我运行程序时,会显示返回屏幕
还有其他方法可以获取 name 的输入吗?
【问题讨论】: