title: Assign txt file data to struct node in linked list
body: <p>Ok so I have never worked with fstream before or opened and read and files in a program. My instructor just gave a few lines of code that open, read, and close a text file. I'm supposed to take the data out of the text file and put it into separate nodes in a linked list and then go on to do other things with it which is not important because I know how to do it. My problem is that I don't know how to a assign these values to the struct values.</p>
  
  <p>The txt file looks like this: </p>
  
  <p>Clark Kent    55000       2500     0.07</p>
  
  <p>Lois Lane     56000       1500     0.06</p>
  
  <p>Tony Stark    34000       2000     0.05</p>
  
  <p>…</p>
  
  <p>I have created a structure called Employee and then basic insert functions so I can add new nodes to the list. Now how do I get these names and numbers into my structure.</p>
  
  <p>here is my code: </p>
  
  <pre><code>#include &lt;fstream&gt;
  #include &lt;iostream&gt;
  using namespace std;
  
  struct Employee
  {
      string firstN;
      string lastN;
      float salary;
      float bonus;
      float deduction;
  
      Employee *link;
  };
  
  typedef Employee* EmployPtr;
  void insertAtHead( EmployPtr&amp;, string, string, float, float,float );
  void insert( EmployPtr&amp;, string, string, float, float,float );
  
  int main()
  {
      // Open file
      fstream in( "payroll.txt", ios::in );
  
      // Read and prints lines
      string first, last;
      float salary, bonus, deduction;
  
      while( in &gt;&gt; first &gt;&gt; last &gt;&gt; salary &gt;&gt; bonus &gt;&gt; deduction)
      {
          cout &lt;&lt; "First, last, salary, bonus, ded: " &lt;&lt; first &lt;&lt; ", " &lt;&lt; last &lt;&lt; ", " &lt;&lt; salary &lt;&lt; ", " &lt;&lt; bonus &lt;&lt; ", " &lt;&lt; deduction &lt;&lt;endl;
      }
  
      // Close file
      in.close();
  
      EmployPtr head = new Employee;
  
  
   }
  
  void insertAtHead(EmployPtr&amp; head, string firstValue, string lastValue,
              float salaryValue, float bonusValue,float deductionValue)
  {
      EmployPtr tempPtr= new Employee;
  
      tempPtr-&gt;firstN = firstValue;
      tempPtr-&gt;lastN = lastValue;
      tempPtr-&gt;salary = salaryValue;
      tempPtr-&gt;bonus = bonusValue;
      tempPtr-&gt;deduction = deductionValue;
  
      tempPtr-&gt;link = head;
      head = tempPtr;
  }
  
  void insert(EmployPtr&amp; afterNode, string firstValue, string lastValue,
          float salaryValue, float bonusValue,float deductionValue)
  {
      EmployPtr tempPtr= new Employee;
  
  
      tempPtr-&gt;firstN = firstValue;
      tempPtr-&gt;lastN = lastValue;
      tempPtr-&gt;salary = salaryValue;
      tempPtr-&gt;bonus = bonusValue;
      tempPtr-&gt;deduction = deductionValue;
  
      tempPtr-&gt;link = afterNode-&gt;link;
      afterNode-&gt;link = tempPtr;
  }
  </code></pre>
  
  <p>Also, I have tried searching this and results have came up but they all opened and read the data differently than what i was given. I am new to c++ coming from java so I do not understand some of the code that I see sometimes.</p>