Проблема "Фантомного студента"
Задача стояла следующая: используя контейнер составить список студентов с ФИО и оценками по трём предметам.
Нуивот, когда приходит время выводить список, самым первым выводится лишний "фантомный" студент, у которого все поля заполнены нулями, а за ним уже все остальные, которые выводятся корректно. Как избавиться от этого призрака?
#include <iostream>
#include <algorithm>
#include <list>
#include <string>
#include <vector>
using namespace std;
struct student
{
string FIO;
int fiz;
int math;
int info;
};
int main(void)
{int N,j;
cout<<"Введите N -- кол-во студентов ";
cin>>N;
list<student> a(N);
list<student>::iterator it; //здесь student -- польз. класс с полями в виде ФИО и оценок
student x;
for (j=0;j<N;j++)
{
cout<<"Insert student's name: "<<endl;
cin>>x.FIO;
cout<<"Insert physics grade: "<<endl;
cin>>x.fiz;
cout<<"Insert math grade: "<<endl;
cin>>x.math;
cout<<"Insert IT grade: "<<endl;
cin>>x.info;
a.push_back(x);
}
cout<<"The list of students: "<<endl;
cout<<endl;
for (it=a.begin();it!=a.end();it++)
{ student x;
x=*it;
cout<<"FIO: ";
cout<<x.FIO<<endl;
cout<<"Physics grade: ";
cout<<x.fiz<<endl;
cout<<"Maths grade: ";
cout<<x.math<<endl;
cout<<"IT grade: ";
cout<<x.info<<endl;
}
return 0;
}