它在循环的第二次迭代中跳过getline函数,并直接跳转到下一条语句。
for (i = 0; i < 5; i++) {
cout << "Movie " << i + 1 << endl;
cout << "Enter name: ";
getline(cin, m[i].name);
cout << "Enter length: ";
cin >> m[i].length;
cout << "Enter ticket: ";
cin >> m[i].ticket;
}
cout << "Entered Details:-\n";
for (i = 0; i < 5; i++) {
cout << m[i].name << endl;
cout << m[i].length << endl;
cout << m[i].ticket << endl;
}
return 0;
}
我希望循环会在第二次迭代中要求我输入名称,但是它会跳过并直接跳转到长度和票证。