Friday, 27 September 2013

getline and passing input streams inside class functions, primary-expression error

getline and passing input streams inside class functions,
primary-expression error

I have a file called grades.txt with some lines of text and integers on it
that i want to read into an already defined class ive created called
Assignment.
int main()
{
ifstream input_file("grades.txt");
Assignment assignment;
input_file >> assignment;
return 0;
}
Above is my main function that will read input_file into the created class
assignment.
friend istream& operator >> (istream& is, Assignment& assignment)
{ // function to read in data to class variables
string line;
getline(*****, line);
// to be able to operate on strings
istringstream iss(line);
// set values read in from input file.
iss >> assignment.Assignment_type;
iss >> assignment.Date;
iss >> assignment.Max_score;
iss >> assignment.Actual_score;
// sometimes Assignment Name will have spaces, have to use getline()
getline(is, assignment.Assignment_name);
return is;
}
Heres the class function that will overload the >> operator to read into
each of the variables in assignment. the group of stars is what im having
problems with, i dont know what to pass to it. I've tried ifstream and
ofstream thinking it was that easy but they return the same error code
P01.cpp:34:21: error: expected primary-expression before ',' token

No comments:

Post a Comment