This is the code for reading from a txt file, but creating a code for writing into a txt file that goes along with this reading code is pretty difficult and am looking for any ideas that can help me in implementing this using linked list along with txt files

I want to create a code to write Into a text file that goes along with the read code that I have listed down all using linked list.
Any ideas would be a big help and appreciated

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

using namespace std;

struct person_tag
{
    string name;
    string id;
};

struct course_tag
{
    string course_name;
    int no_of_units;
    int marks[4];
    double avg;
};

struct tutor_tag
{
    person_tag tutor_info;
    course_tag course_info;
    tutor_tag *next;
};

typedef struct tutor_tag Tutor_Tag;
typedef Tutor_Tag *Tutor_TagPtr;

Tutor_Tag *hptr;
Tutor_Tag *cptr;
Tutor_Tag *nptr;

//function protypes
void menu();
void read();
void display_tutors();

void
read()              //readfile function
{
    hptr = nptr = NULL;              //intialized to null
    string filename = "tutors.txt";
    ifstream inFile(filename);

    if (inFile.fail())               // if file doesnt open successfully
    {
    cout << "The File was not opened successfully\n";
    cout << "Please check that the file currently exists\n";
    exit(1);
    }
    while (true)         // until the end of the file
    {
    cptr = new Tutor_Tag;
    cptr->next = NULL;
    // Read the data into the new item
    inFile >> cptr->tutor_info.name;
    inFile >> cptr->tutor_info.id;
    inFile >> cptr->course_info.course_name;
    inFile >> cptr->course_info.no_of_units;
    for (int j = 0; j < cptr->course_info.no_of_units; j++) {
        inFile >> cptr->course_info.marks[j];
    }

    // Did you read it okay?
    if (inFile.fail()) {
        delete cptr;    // don't need it
        break;
    }

    // Okay, you read it. Add to the list
    if (hptr == NULL) {
        // First item in the list. Point hptr at it
        hptr = cptr;
    } else {
        // Not the first item, append it to the tail.
        nptr->next = cptr;
    }
    nptr = cptr;        // Move the tail pointer
    }
    inFile.close();              //close file
}

void
display()
{
    tutor_tag *ptr;
    ptr = hptr;
    while (ptr != NULL) {
    cout << "The Tutor Name: " << ptr->tutor_info.name << "  \n";
    cout << "The Tutor ID: " << ptr->tutor_info.id << "  \n";
    cout << "The course name: " << ptr->course_info.course_name << "  \n";
    cout << "Number of units " << ptr->course_info.no_of_units << "  \n";
    cout << " Rating recieved: \n";
    for (int j = 0; j < ptr->course_info.no_of_units; j++) {
        cout << ptr->course_info.marks[j] << "  \n";
    }
    cout << "The marks average is : " << ptr->course_info.avg << "  \n";
    ptr = ptr->next;
    }
}

int
main()
{
    read();
    cout << "The linked list is: ";
    display();
    return 0;
}
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.