-2

I think I am messing up somewhere between the pointers. I do not know if I am supposed to change Book* to something or not.

Any help will be appreciated. Thank You.

istream& operator >> (istream& is, Warehouse& warehouse){

    int counter = 0;
    Book* temp;
    Book* headNode;

    is >> headNode;
    while (!is.eof()){
        temp = headNode;
        is>> headNode;
        headNode.setNext(temp); 
        counter++;
    }
    warehouse.bookCount = counter; 
    warehouse.head = headNode;
    return is;
}

1 Answers1

2

Problem 1

is >> headNode;

is wrong. Reading a pointer from a file does not make sense. There are two such lines in your posted code.

Problem 2

while (!is.eof()){

is wrong. See Why is iostream::eof inside a loop condition considered wrong?

I am not able to suggest a fix without seeing the contents of the file from which you are trying to read the linked list data.

R Sahu
  • 196,807
  • 13
  • 136
  • 247