こんにちは皆構造化データのプログラミング割り当てをしています。構造体の仕組みを理解していると思います。getlineをスキップするgetline
私は学生名、ID番号(A-Numbers)、およびその残高のリストを読み込もうとしています。
私は自分のコードをコンパイルすると、最初はすべてが読み込まれますが、2回目はループの周りと毎回ユーザ名の入力を求められますが、getlineをスキップしてA- Aナンバー入力。
ご協力いただければ幸いです。ループが周回するたびにgetlineを動作させる方法を理解しようとしています。
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main(){
const int maxStudents = 30;
struct Students{
string studentName;
int aNumber;
double outstandingBalance;};
Students students[maxStudents];
for(int count = 0; count < maxStudents-1; count++)
{
cout<<"Student Name:";
cin.ignore();
getline(cin,students[count].studentName);
cout<<"\nA-Number:";
cin>>students[count].aNumber;
if(students[count].aNumber == -999)
break;
cout<<"\nOutstanding Balance:";
cin>>students[count].outstandingBalance;
}
cout<<setw(20)<<"A-Number"<<"Name"<<"Balance";
for(int count2 = 29; count2 >= maxStudents-1; count2--)
cout<<setw(20)<<students[count2].aNumber<<students[count2].studentName<<students[count2].outstandingBalance;
system("pause");
return 0;
}
'cin >> students [count] .studentName;'を使うことはできません。それは – Neox
@ Neoxさんの作品です - 学生の名前に「John Hancock」のようなスペースがある場合はそうではありません。 –