Hello everyone, my classmate is making a library manager program and he was able to read the items on the txt file, however when we run his program a couple of times it did not read the txt file again can someone help us with this?

#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>

using namespace std;

struct book
{
    string ISBN;
    string author;
    string title;
    string publisher;
    string cpyryt;
    int quantity;
    int qborrowed;
    book *link;
};

class Library
{
public:
    void addBook();
    void searchBook();
    void removeBook();
    void editBook();
    void borrowBook();
    void returnBook();
    void sortList();
    void viewList();

    void displayMenu();
    void readFile();
};

int main()
{
    Library obj;
    //obj.addBook();
    obj.viewList();


    system("pause");
    return 0;
}

void Library::addBook()
{
    Library obj;

    book *head = NULL;
    book *newBook;
    book *current = head;

    ifstream infile;
    infile.open("LibraryData.txt");

    if (infile.is_open())
    {
        while (!infile.eof())
        {
            newBook = new book;

            infile.ignore(100,'#');
            getline(infile,newBook->ISBN);
            infile.ignore(100,'#');
            getline(infile, newBook->author);
            infile.ignore(100,'#');
            getline(infile, newBook->title);
            infile.ignore(100,'#');
            getline(infile, newBook->publisher);
            infile.ignore(100,'#');
            getline(infile, newBook->cpyryt);
            infile >> newBook->quantity;
            infile >> newBook->qborrowed;

            newBook->link = NULL;

            if (head == NULL)
            {
                head = newBook;
                current = newBook;
            }
            else
            {
                current->link = newBook;
                current = newBook;
            }               
        }
    }
    infile.close();

    ////--------------get data from user

    //newBook = new book;
    //
    //cout<<"Enter the ISBN: ";
    //getline(cin,newBook->ISBN);
    //cout<<"Enter the author of the book: ";
    //getline(cin,newBook->author);
    //cout<<"Enter the title of the book: ";
    //getline(cin,newBook->title);
    //cout<<"Enter the publisher of the book: ";
    //getline(cin,newBook->publisher);
    //cout<<"Enter the copyright date: ";
    //getline(cin,newBook->cpyryt);
    //newBook->quantity = 1;
    //newBook->qborrowed = 0;

    //newBook->link = NULL;

    //if (head == NULL)
    //{
    //  head = newBook;
    //  current = newBook;
    //}
    //else
    //{
    //  current->link = newBook;
    //  current = newBook;
    //} 
    //

    ////-------------save data to file
    //ofstream outfile;
    //outfile.open("LibraryData.txt");
    //outfile.clear();

    //current = head;
    //while (current != NULL)
    //{
    //  outfile<<"#"<<current->ISBN;
    //  outfile<<"\n#"<<current->author;
    //  outfile<<"\n#"<<current->title;
    //  outfile<<"\n#"<<current->publisher;
    //  outfile<<"\n"<<current->cpyryt;
    //  outfile<<"\n"<<current->quantity;
    //  outfile<<"\n"<<current->qborrowed;
    //  current = current->link;
    //}
    //outfile.close();
}

void Library::viewList()
{
    book *head = NULL;
    book *newBook;
    book *current = head;

    ifstream infile;
    infile.open("LibraryData.txt");

    if (infile.is_open())
    {
        while (!infile.eof())
        {
            newBook = new book;

            infile.ignore(100,'#');
            getline(infile,newBook->ISBN);
            infile.ignore(100,'#');
            getline(infile, newBook->author);
            infile.ignore(100,'#');
            getline(infile, newBook->title);
            infile.ignore(100,'#');
            getline(infile, newBook->publisher);
            infile.ignore(100,'#');
            getline(infile, newBook->cpyryt);
            infile >> newBook->quantity;
            infile >> newBook->qborrowed;

            newBook->link = NULL;

            if (head == NULL)
            {
                head = newBook;
                current = newBook;
            }
            else
            {
                current->link = newBook;
                current = newBook;
            }               
        }
    }
    infile.close();

    cout<<"South Hub Institute of Technology"
        <<"\nLibrary"<<endl;

    current = head;
    while (current != NULL)
    {
        cout << "--------------------------------------------------------------------------------" << endl;
        cout << current->ISBN << "\t" << current->title << endl;
        cout << "\t\t\t" << current->author << endl;
        cout << "\t\t\t" << current->publisher << endl;
        cout << "\t\t\t" << current->cpyryt << endl;
        current = current->link;
    }
}

void Library::displayMenu()
{

}

Post some lines from the text file.

infile.ignore(100,'#');

Why the above lines?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.