Code: Select all
#include <wx/list.h>
#include <wx/ffile.h>
#include <wx/listimpl.cpp>
#include <iostream>
using namespace std;
class Customer
{
public:
int CustID=1;
wxString CustName=wxString("temple string");
wxPoint CustPoint=wxPoint(0,0);
double Value=1.1;
bool SaveObjects( wxFFile &fFile )
{
fFile.Write( &CustID, sizeof( CustID ) );
fFile.Write( &CustName, sizeof( wxString ) );
fFile.Write( &CustPoint, sizeof( wxPoint ) );
fFile.Write( &Value, sizeof( Value ) );
}
bool LoadObjects( wxFFile &fFile )
{
fFile.Read( &CustID, sizeof( CustID ) );
fFile.Read( &CustName, sizeof( wxString ) );
fFile.Read( &CustPoint, sizeof( wxPoint ) );
fFile.Read( &Value, sizeof( Value ) );
}
};
void DDDialog::OnAbout(wxCommandEvent& event)
{
wxFFile m_fFile;
m_fFile.Open( wxT("data.txt"), "a+b" );
Customer* Cust = new Customer;
Cust->CustID=wxAtoi(TextCtrl1->GetValue());
Cust->CustName=TextCtrl2->GetValue();
Cust->CustPoint=wxPoint(wxAtoi(TextCtrl3->GetValue()),0);
Cust->Value=wxAtof(TextCtrl4->GetValue());
Cust->SaveObjects(m_fFile);
delete Cust;
m_fFile.Close();
}
void DDDialog::OnButton3Click(wxCommandEvent& event)
{
system("cls");
wxFFile m_fFile;
m_fFile.Open( wxT("data.txt"), "rb" );
Customer* Cust = new Customer;
while(!m_fFile.Eof())
{
Cust->LoadObjects(m_fFile);
cout<<"TextCtrl1:"<<Cust->CustID<<endl;
cout<<"TextCtrl2:"<<Cust->CustName<<endl;
cout<<"TextCtrl3:"<<Cust->CustPoint.x<<endl;
cout<<"TextCtrl4:"<<Cust->Value<<endl;
}
cout<<endl;
delete Cust;
m_fFile.Close();
}