I keep getting a read access violation. Here is the code that I have.
class List
{
public:
List();
List(const List ©);
~List();
/*List & operator=(const List &rhs);
Record * headPtr() const;
void setheadptr(Record * const newhead);
bool insertatfront(Record newdata);*/
void importcourselist();
void Loadmasterlist();
void storemasterlist();
Record *makenode(fstream &file);
Record *makenode(ifstream &file);
private:
Record *mHead;
Record *mEnd;
};
List::List()
{
mHead = nullptr;
mEnd = nullptr;
}
void List::storemasterlist()
{
ofstream outfile;
outfile.open("masterlist.txt");
mEnd = mHead;
while (mEnd->getnext()!= nullptr)
{
outfile << mEnd << endl;
mEnd = mEnd->getnext();
}
outfile << mEnd;
}
I'm not exactly sure what is going on but, every time I try to debug it it'll send me to the getter function for my pointer which looks like this:
Record *Record::getnext()
{
return mnext;
}
I believe that my error lies somewhere in my import function. This is where I'm creating the extra empty node.
void List::importcourselist()
{
ifstream infile;
string ptoken;
infile.open("studentlist.csv");
getline(infile, ptoken);
mHead = makenode(infile);
mEnd = mHead;
while (!infile.eof())
{
mEnd->setnext(makenode(infile));
mEnd = mEnd->getnext();
}
infile.close();
}