Read records from file and store in dynamic array

So i have to define Student class, read the number of records in the input file, create a dynamic array of Students, read the records from the file and store them into a dynamic array and print the records.

This is records.txt
6 //number of records
123 Jose Garcia 99
345 Luis Garcia 87
234 Jazlyn Soriano 79
456 Carter Sandoval 95
567 Natalia Soto 67
789 Isabel Santana 80

This only outputs 6123 6 times.
How can i have the array not read the first line in the file? Why is it only printing 6 and 123?


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
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
using namespace std;
void readNbOfRecs();
class Student
{

public:
	Student();
	Student(int, string, string, int);
	void setIdandGrade(int, int);	
	void readftoa();
	int id;
	string firstName;
	string lastName;
	int examGrade;
};

int main()
{
	Student *records;
	records = new Student[6];
	readNbOfRecs();

	int id, examGrade;
	string firstName, lastName;
	
	fstream gradebook;
	gradebook.open("C://Users//Esmeralda//Desktop//Records.txt",ios::in);
	if (gradebook.fail())
		{
			cout << "Error opening file" << endl;
			exit(0);
		}
	for (int i=0; i<6;i++)
	{
		gradebook >> id >> firstName >> lastName >> examGrade;
		records[i]=Student(id, firstName, lastName, examGrade);
		cout << id << firstName, lastName, examGrade;
	}


	system("pause");
	return 0;
}
void readNbOfRecs()
{
	fstream gradebook;
	gradebook.open("C://Users//Esmeralda//Desktop//Records.txt",ios::in);
	if (gradebook.fail())
	{
		cout << "Error opening file" << endl;
		exit(0);
	}
	int nbRec;
	gradebook >> nbRec;

	gradebook.close();
}
Student::Student()
{
	id=000;
	firstName=" ";
	lastName=" ";
	examGrade=0;
}
Student::Student(int theId, string theFirst, string theLast, int theGrade)
{
	setIdandGrade(theId,theGrade);
}
void Student::setIdandGrade(int theId, int theGrade)
{
	if(theId<1000 & theId>=100)
		exit(0);
	if(theGrade<101 & theGrade>=0)
		exit(0);
}
Edit: So i fixed my dumb mistake on line 41 to
 
cout << id << "\t" << firstName << "\t" << lastName << "\t" << examGrade;


but it prints crazy! it seems to only print 6 123 Jose Garcia repeatedly and not the rest?
Topic archived. No new replies allowed.