Help with getline.

I am writing a program that will serves as a gradebook, it's an programming assignment by the way. Everything worked flawlessly up until my teacher told me to get the input data from a file. Getting data from the user using "cin" I don't have and problem, but getting data from a file, I get several errors. Please help me.

These are the errors I get.

line 27: error: could not convert myfile.std::basic_ios<_CharT, _Traits>::eof [with _Chart = char, _Traits = std::char_traits<char>]' to 'bool'
line 27: error: in argument to unary!
line 34: error: no matching functionfor call to 'getline<std::ifstream$, char$>'
line 35: error: no matching functionfor call to 'getline<std::ifstream$, char$>'
line 36: error: no matching functionfor call to 'getline<std::ifstream$, char$>'
line 37: error: no matching functionfor call to 'getline<std::ifstream$, char$>'
line 38: error: no matching functionfor call to 'getline<std::ifstream$, char$>'

here's what should be inputed:

The input begins with an integer N, 0 < N ≤ 50, which specifies the number of student records. Each record consists of eight lines:

ID number
last name
first name
middle initial
quiz 1 score
quiz 2 score
midterm exam score
final exam score

example input:

2
2012-1-1000
Weston
Blake
N
6
6
60
60

2012-1-1098
Espinoza
Hayley Rose
T
10
10
100
100

sample output:

ID Number: 2012-1-1000
Name: Weston, Blake N.
Q1: 6
Q2: 6
ME: 60
FE: 60
NG: 60
LG: D

ID Number: 2012-1-1098
Name: Espinoza, Hayley Rose T.
Q1: 10
Q2: 10
ME: 100
FE: 100
NG: 100
LG: A

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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
  #include <iostream>
#include <string>
#include <fstream>
using namespace std;

#define N 51

struct gradebook_t {
  string IdNum;
  string lastname;
  string firstname;
  char MI;
  int q1;
  int q2;
  int midex;
  int finex;
} gradebook [N];

void printgrade (gradebook_t gbook);

int main (){
  ifstream myfile;
  int i, x;
  
  myfile.open("LAB08.in");

while(!myfile.eof){  
  myfile >> i;
  for (x=0; x<i; x++)
  {
    getline(myfile,gradebook[x].IdNum);
	getline(myfile,gradebook[x].lastname);
	getline(myfile,gradebook[x].firstname);
	getline(myfile,gradebook[x].MI);
	getline(myfile,gradebook[x].q1);
	getline(myfile,gradebook[x].q2);
	getline(myfile,gradebook[x].midex);
	getline(myfile,gradebook[x].finex);
	cout << "\n";
  }
}
  
  for (x=0; x<i; x++){
    if ((gradebook[x].q1 <= 10) && (gradebook[x].q2 <= 10) && (gradebook[x].midex <= 100) && (gradebook[x].finex) <= 100){
	printgrade (gradebook[x]);
	}
	else
	cout << "invalid grades for " << gradebook[x].IdNum << "\n\n";
  }
  myfile.close();
  return 0;
}

void printgrade (gradebook_t gbook){
double qper, midper, finper, fgrade;
int ng;

qper = ((gbook.q1+gbook.q2) / 20.0) * 25.0;
midper = (gbook.midex / 100.0) * 25.0;
finper = (gbook.finex / 100.0) * 50.0;
fgrade = qper+midper+finper;
ng = static_cast<int>(fgrade + 0.5);

  cout << "ID Number: " << gbook.IdNum;
  cout << "\n" << "Name: " << gbook.lastname << ", " << gbook.firstname << " " << gbook.MI << ".";
  cout << "\n" << "Q1: " << gbook.q1;
  cout << "\n" << "Q2: " << gbook.q2;
  cout << "\n" << "ME: " << gbook.midex;
  cout << "\n" << "FE: " << gbook.finex;
  cout << "\n" << "NG: " << ng;
  cout << "\n" << "LG: ";
  
  if (fgrade >= 90.0)
		cout << "A";
		
  if ((fgrade >= 80.0) && (fgrade < 90.0))
		cout << "B";

  if ((fgrade >= 70.0) && (fgrade < 80.0))
		cout << "C";

  if ((fgrade >= 60.0) && (fgrade < 70.0))
		cout << "D";
  if (fgrade < 60.0) 
		cout << "F";
  
  cout << "\n\n";
}
line 27: while(!myfile.eof()){

the problem with the getline(); is that the type of the second parameter is incorrect...must be std::string

otherwise look at: http://www.cplusplus.com/reference/istream/istream/getline/

Aceix.
thanks Aceix, I'll check it now.
Hi Aceix, I edited my code like this

1
2
3
4
5
6
7
8
9
10
11
12
13
14
while(!myfile.eof){  
  myfile >> i;
  x=0;
    getline(myfile,gradebook[x].IdNum);
	getline(myfile,gradebook[x].lastname);
	getline(myfile,gradebook[x].firstname);
	myfile >> gradebook[x].MI;
	myfile >> gradebook[x].q1;
	myfile >> gradebook[x].q2;
	myfile >> gradebook[x].midex;
	myfile >> gradebook[x].finex;
	cout << "\n";
  x++;
}


the getline errors we're cleared by the error in line 27 is still there. the output is still:

line 27: error: could not convert myfile.std::basic_ios<_CharT, _Traits>::eof [with _Chart = char, _Traits = std::char_traits<char>]' to 'bool'
line 27: error: in argument to unary

What's wrong with my program?
I fixed the problem, the program is running now without errors. But the problem now is that when I run it, It outputs infinite blank lines. Can somebody help me?
Topic archived. No new replies allowed.