Here's my code. Purpose is to input a Vector of Student class, contain name and homework grades.
istream& input(istream& is, student& s){
is.clear();
cout << "Enter student name: ";
getline(is,s.name);
grade(is,s.homework);
return is;
}
istream& grade(istream& is, vector<double>& homework){
if(is){
homework.clear();
double x;
cout << "Enter grade of student - Ctrl-Z to stop: ";
while(is>>x)
homework.push_back(x);
is.clear();
}
return is;
}
The problem is that the first student's name is ok, but when the program read the next student's name (Input from keyboard), it always starts with the substitute (ASCII 26) character. I guess the problem comes from input stream, when I used CTRL - Z to signal the end of the homework grades input. Can you guys suggest a solution ?