title: filling a struct from a text file in C++
body: <p>guys, I have a text "sales.txt" file which contains (id, lastname, quarter, sales) in the following format.</p>
  
  <pre><code>123 smith 1 333.20
  221 doe 1 345.50
  342 johnson 1 774.50
  123 smith 2 333.20
  221 doe 2 555.50
  342 johnson 2 25.50
  123 smith 3 254.20
  221 doe 3 652.50
  342 johnson 3 32.50
  123 smith 4 354.20
  221 doe 4 51.50
  342 johnson 4 1000.50
  </code></pre>
  
  <p>I'm trying to put the file into a struct for output to another text file, but so far I'm having problem with extracting the "id" and lastname. here's a portion of the code. The second method is to extract the sale by quarter and put it into array, but is not working, if someone could give me a hand with both methods</p>
  
  <p>thanks</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;fstream&gt;
  
  using namespace std;
  
  struct employees { int id; string lname; double qtrSale[4]; double tsale; }; 
  void getIdName(employees list[], ifstream&amp; infile, int num);
  
  int main()
  {
  
  ifstream infile;
      string file("file1.txt");
  
      infile.open(file);
      employees list[lsize];
      getIdName(list, infile, lsize);
      /*getData(list, file, lsize);*/
  
      for(int i = 0; i &lt; lsize; i++)//checking struct
      {
          cout &lt;&lt; list[i].id &lt;&lt; " " &lt;&lt; list[i].lname &lt;&lt; endl;
      }
  }
  
  void getIdName(employees list[], ifstream&amp; infile, int lsize)
  {
      int id; 
      string lname; 
      double sale, temp;
  
      for(int i = 0; i &lt; lsize; i++)
      {
          infile &gt;&gt; list[i].id &gt;&gt; list[i].lname &gt;&gt; temp &gt;&gt; sale;
          /*for(int j = 1; j &lt;= 4; j++)
          {
              list[i].qtrSale[j] = 0.0;
          }*/
  
      }
  }
  
  void getData(employees list[], string file, int lsize)
  {
      int id, qtr; 
      double amount;
      ifstream infile(file);
      while(infile.good())
      {
          for(int j = 0; j &lt; lsize; j++)
          {
              infile &gt;&gt; id;
              for(int i = 1; i &lt;= 4; i++)
              {
                  infile &gt;&gt; qtr &gt;&gt; amount;
                  if(list[j].id == id &amp;&amp; qtr == 1) { list[j].qtrSale[i] = amount; }
                  if(list[j].id == id &amp;&amp; qtr == 2) { list[j].qtrSale[i] = amount; }
                  if(list[j].id == id &amp;&amp; qtr == 3) { list[j].qtrSale[i] = amount; }
                  if(list[j].id == id &amp;&amp; qtr == 4) { list[j].qtrSale[i] = amount; }
              }
          }
      }
  }
  </code></pre>