Mình có 2 struct như thế này. khi mình lưu thông tin của 1 máy bay thì thì khi đọc lên thì không đọc được cái DSLKĐ chuyến bay. Vì bản chất là ghi địa chỉ con trỏ. Mọi người giúp mình làm sao để đọc ghi file với ạ.Bên dưới là cấu trúc và hàm đọc ghi file của mình
struct Airplane
{
char id[30];
int nChair;
LIST_FLIGHT listFlight;
};
typedef struct Airplane AIRPLANE;
typedef AIRPLANE* PTR_AIRPLANE;
struct ListAirplane
{
int n = 0;
PTR_AIRPLANE *listAirplane = new PTR_AIRPLANE[MAX_AIRPLANE];
};
typedef struct ListAirplane LIST_AIRPLANE;
typedef LIST_AIRPLANE* PTR_LIST_AIRPLANE;
struct Flight
{
int nTicket = 0;
char id[30], destiny[100];
DateTime dateLeave;
int stt = STT_REMAIN_TICKET;
int nTicketSold = 0, nTicketRemain = 0;
Ticket *listTicket = new Ticket[MAX_TICKET];
};
typedef struct Flight FLIGHT;
struct NodeFlight
{
FLIGHT data;
struct NodeFlight *pNext;
};
typedef struct NodeFlight NODE_FLIGHT;
struct ListFlight
{
NODE_FLIGHT *pHead, *pTail;
};
typedef struct ListFlight LIST_FLIGHT;
void SaveAirplane(PTR_LIST_AIRPLANE pListAirplane) {
fstream myfile("airplane.txt", ios::out | ios::binary);
int SizeData = sizeof(AIRPLANE);
for (int i = 0; i < pListAirplane->n; i++) {
myfile.write(reinterpret_cast<const char*>(pListAirplane->listAirplane[i]), SizeData);
}
myfile.close();
}
void LoadAirplane(PTR_LIST_AIRPLANE &pListAirplane) {
fstream Myfile;
Myfile.open("airplane.txt", ios::in | ios::binary);
PTR_AIRPLANE temp;
while (!Myfile.eof())
{
temp = new AIRPLANE;
Myfile.read(reinterpret_cast<char*>(temp), sizeof(AIRPLANE));
if (!Myfile.eof()) pListAirplane->listAirplane[pListAirplane->n++] = temp;
else delete temp;
}
Myfile.close();
}
Mình nghĩ là nếu lưu xuống là thông tin. Thì khi đưa lên. Bạn sẽ đọc dữ liệu sau đó rồi tạo ra một con trỏ để đưa giá trị vào