title: How do i write linked list as an object to a file
body: <p>In this function I am trying to write the information from the linked list to a file</p>
  
  <pre><code>class Employer: public People{
  
              void tryWrite(){
  
                  ofstream file("Employer.dat",ios::out|ios::app| ios::binary);
  
  
                  if(file.is_open()){
  
  
                      file&lt;&lt;getFirstName()&lt;&lt;" "&lt;&lt;getLastName()&lt;&lt;" " &lt;&lt; companyName&lt;&lt;" "&lt;&lt;position&lt;&lt;" "&lt;&lt;getTelHome()&lt;&lt;" "&lt;&lt;getTelMobile()&lt;&lt;" " &lt;&lt;email&lt;&lt;" "&lt;&lt;getAddress()&lt;&lt; endl;
  
                      file.close();
                  }
  
              }
  
  
      };
      #endif
  </code></pre>
  
  <p>This is the linked list manipulator for the employer class</p>
  
  <p>At this point in the writeFile function I am trying to traverse through the link list and call the tryWrite function in Employer.h to write to the actual data in the link list to file</p>
  
  <pre><code>  class EmployerList
    {
      private:
  
          Employer *head;//employee pointer(head pointer)
  
      public:     
  
     void writeFile(){
  
       Employer *temp = head;
          while (temp != NULL)
          {
  
              temp-&gt;tryWrite();//Employee's display method called here
              temp = temp-&gt;getNext();
          }
  
  
    }
  </code></pre>
  
  <p>In this read function I would like to read the data in the following order Name: Jane brown Company's name: Lime Position: clerk Address:
  New Kingston Home#: 876-466-8778 Mobile #: 543-455-6344 Email: dumb@yahoo.com</p>
  
  <p>But reading directly from the file the data is Jane brown Lime clerk
   New Kingston 876-466-8778 543-455-6344 dumb@yahoo.com</p>
  
  <p>when it gets to the address it will display as: Address: New </p>
  
  <p>instead of: Address: New Kingston</p>
  
  <p>The null spaces is creating the issue and i do not know how to get it
   to do what i want</p>
  
  <p>void TestRead(){</p>
  
  <pre><code>    ifstream tryRead("em.dat", ios::in|ios::binary);
  
  
      string Email,  cName, pos,fName,lName,addr, tHome,tMobile;
  
  
      while(tryRead&gt;&gt;fName&gt;&gt;lName&gt;&gt;cName&gt;&gt;pos&gt;&gt;addr&gt;&gt;tHome&gt;&gt;tMobile){
  
          cout&lt;&lt;"Name: "&lt;&lt;fName&lt;&lt;lName&lt;&lt;endl;
          cout&lt;&lt;"Comapny's Name: "&lt;&lt;cName&lt;&lt;endl;
          cout&lt;&lt;"Position: "&lt;&lt;pos&lt;&lt;endl;
          cout&lt;&lt;"Address: "&lt;&lt;addr&lt;&lt;endl;
          cout&lt;&lt;"Home#: "&lt;&lt;tHome&lt;&lt;endl;
          cout&lt;&lt;"Mobile#: "&lt;&lt;tMobile&lt;&lt;endl;
  
                        tryRead.close();
      }
  
  
  } 
  
  
  };
          #endif
  </code></pre>
  
  <p>This is main which populate the linked list with data</p>
  
  <pre><code> #include &lt;iostream&gt;
      #include &lt;string&gt;
      #include "Employer.h"
      #include "EmployerList.h"
  
      using namespace std;
  
      void main()
      {
  
          EmployerList em;
  
          em.AddNode("nim@yahoo.com", "LIME", "Manager", "Tashauna", "Simon", "New Kingston", "876-985-8337", "876-405-3536");
  
          em.AddNode("ker@gmail.com", "NOKIA", "CEO", "Keric", "McDonald", "Europe", "0411-789-6548", "985-257-1111"); 
  </code></pre>
  
  <p>After the linked list is filled with data the write file function in EmployerList.h is called</p>
  
  <pre><code>        em.writeFile();
  
     em.TestRead(); 
  
  
  
  
          system("pause");
  
      }
  </code></pre>