getline()

My program retrieves lines of text from a file and gathers the last character in each line. But in my code, I can't seem to retrieve the last character of the last line.

Here's the important parts:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
double gpa(ifstream& stream){
	string lineFromTextFile = "";
	string oneLetter = "";
	const char *letterGrade;
	bool endOfFile = false;
	double totalGPA = 0.0;
	int howManyGradesCounted = 0;

	getline(stream,lineFromTextFile);

	while(!stream.eof()){
	 
	// Getting the last character in the line
	 oneLetter = lineFromTextFile.substr(lineFromTextFile.length() - 1,1);
	 // converting that one letter into a char
	 letterGrade = oneLetter.c_str();   
	 // adding the letter's corresponding GPA to the running total
         // gpa(letterGrade) returns a number corresponding to letter's GPA
	 totalGPA += gpa(letterGrade);
         // Getting next line
	 getline(stream,lineFromTextFile);
         // Keeping track of how many numbers have been counted
	 howManyGradesCounted++;


	}
         // returning average of gpa
	 return totalGPA / howManyGradesCounted;
}


stream.eof() is found and doesn't retrieve the last line's char. How can I get it?
Topic archived. No new replies allowed.