0

I'm working on a project that requires files to be used only twice throughout the program–one time to load data in the beginning, and one time to save data at the end. The data is 3 arrays of structs, like a database of sorts. Here's their code.

struct patient {
    string id;
    string username;
    string password;
    string name;
    int age;
} infoPatients[PATIENT_NUM];
struct doc {
    string id;
    string username;
    string password;
    string name;
} infoDocs[DOC_NUM];
struct appoint {
    string index;
    patient appointPatient;
    doc appointDoc;
    date appointDate;
    string timeSlot;
}infoAppoints[APPOINT_NUM];

And this is the date struct:

        struct date {
    int day;
    int month;
    int year;
};

I think what I need to do is create 3 files, one for each struct array, and store 1 array element in each line. Each line will contain the struct members delimited by any delimiter character. But I have no idea what functions to use.

Apologies if this is a ridiculous question. Please feel free to redirect me to a similar question or any resource that will help me out, but if you could help me directly it would be much appreciated!

  • I would expect your course materials to have all the information you need to complete this assignment. The verb for writing a struct/class to a stream is "serialize". – jthill May 08 '22 at 18:27
  • Just decide your file format and then implement with fstream (as you tagged). Why do not? What is actual problem? – fana May 09 '22 at 02:11
  • @jthill We haven't studied file handling as part of our course but we've been allowed to use it to make testing easier (so far we've been manually registering lots of users every run). And unfortunately this is someone else's part on the project that I'm having to take over due to them slacking, which is why I'm struggling with it. Thank you!! – Nono May 09 '22 at 03:15
  • @Borgleader Absolutely! I was missing the term 'serialize' so I should be able to research this better now. Thank you!! – Nono May 09 '22 at 03:20
  • @fana I geniunely had no idea how to start or even how to research this, had a bit of a derp moment – Nono May 09 '22 at 03:21
  • If I was you, I'll research about the usage of `fstream`. Then test it with some very simplified cases. e.g. trial and error about "to restore the `string`, what is needed to be written in file?" – fana May 09 '22 at 04:06
  • You said "store 1 array element in each line. Each line will contain the struct members delimited by any delimiter character. " ...Is this a real requirement? I think some format that used in general is easier to consider (e.g. such as INI, JSON, etc). – fana May 09 '22 at 04:18

0 Answers0