I am working on a MFC application witch needs to store data on a file
I have a class like this
class Client
{
public:
Client(CString Name , CString LastName , CString Id );
int create();
int update(Client & myClient);
CString name;
CString lastName;
CString id;
};
Client::Client(CString Name , CString LastName , CString Id )
{
name = Name;
lastName=LastName;
id=Id;
}
void displayMessage(CString message , CString title=L"Meesage")
{
MessageBox(NULL,message,title,MB_OK | MB_ICONERROR);
}
int Client::create(Client myClient)
{
ofstream output;
output.open("test.dat" , ios::binary );
if( output.fail() )
{
CString mess;
mess = strerror( errno );
displayMessage(mess);
return 1 ;//anything but 0
}
output.write( (char *) &myClient , sizeof(Client));
output.close();
return 0;
}
int Client::update(Client & myClient)
//also tried passing by value : int update(Client myClient)
{
ifstream input;
input.open("test.dat" , ios::binary );
if( input.fail() )
{
CString mess;
mess = strerror( errno );
displayMessage(mess);
return 1 ;//anything but 0
}
input.read( (char *) &myClient , sizeof(Client));
input.close();
return 0;
}
Create function works well ,
But , about update function I have some problems
I use function like this:
Client myClient();
myClient.update(myClient);
But I got this error when I run this function
Unhandled exception at 0x5adfab2a (mfc100ud.dll) in MyProject.exe: 0xC0000005: Access violation writing location 0x039708fc.
What Can I do?