title: reading data from files
body: <p>I am working on a MFC application witch needs to store data on a file</p>
  
  <p>I have a class like this</p>
  
  <pre><code>class Client
  {
  public:
      Client(CString Name , CString LastName , CString Id );
      int create();
      int update(Client &amp; 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 *) &amp;myClient , sizeof(Client));
          output.close();
  
          return 0;
      }
  
  
      int Client::update(Client &amp; 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 *) &amp;myClient , sizeof(Client));
          input.close();
  
          return 0;
      }
  </code></pre>
  
  <p>Create function works well ,</p>
  
  <p>But , about update function I have some problems</p>
  
  <p>I use function like this:</p>
  
  <pre><code>Client myClient();
  myClient.update(myClient);
  </code></pre>
  
  <p>But I got this error when I run this function</p>
  
  <pre><code> Unhandled exception at 0x5adfab2a (mfc100ud.dll) in MyProject.exe: 0xC0000005: Access violation writing location 0x039708fc.
  </code></pre>
  
  <p>What Can I do?</p>