So I\'m trying to read input like this from the standard input (using cin
):
Adam English 85
Charlie Math 76
Erica His
You cannot std::getline()
a std::stringstream
; only a std::string
. Read as a string, then use a stringstream to parse it.
struct Student
{
string name;
string course;
unsigned grade;
};
vector students;
string s;
while (getline( cin, s ))
{
istringstream ss(s);
Student student;
if (ss >> student.name >> student.course >> student.grade)
students.emplace_back( student );
}
Hope this helps.