I'm defining a member function for a class Queue that is essentially a linked list with nodes of class Car. I'm trying to make a class method that reads the queue from file row by row. I edited in a bunch of cout statements to track each iteration and I can see my test file is getting to the point where it's been turned into an instance of the node class. But then my output is a queue with a single node but a count attribute that reflects the nodes that disappeared. Here's my function:
void Queue::read(string filename)
{
ifstream in;
in.open(filename);
Car temp;
Car last;
string name;
string model;
string plate;
string vip;
getline(in, name);
while (!in.eof()) {
last = temp;
getline(in, name);
getline(in, model);
getline(in, plate);
getline(in, vip);
if (vip == "1") {
temp = Car(name, model, plate, true);
}
else {
temp = Car(name, model, plate, false);
}
count++;
if (count == 1) {
front = &temp;
}
else {
last.next = &temp;
back = &temp;
}
}
last.next = NULL;
in.close();
std::cout << endl << *front;
}
I must be overlooking something here. The first getline() statement is just to get rid of a new line that gets inserted but the output function. Normally a node that's been output to file looks something like:
First Last
Model XXXX
AAA123
0