title: How do I read in a specified number of characters from a file while still iterating through it?
body: <p>I have a file of data like this:</p>
  <pre class="lang-none prettyprint-override"><code>    Judy Henn      2 Oaklyn Road       Saturday 2001
      Norman Malnark 15 Manor Drive      Saturday 2500
      Rita Fish      210 Sunbury Road    Friday   750
  </code></pre>
  <p>I need to assign the first 20 characters as the name, next 20 as address, next 10 as day, and the number as yardSize, using the <code>istream::get()</code> method. My professor is requiring the use of <code>.get()</code> to accomplish this.</p>
  <p>I am having a really hard time figuring out how to assign the data from the file to the right variables while still looping.</p>
  <pre><code>struct Customer{
      char name[21];
      char address[21];
      char day[11];
      int yardSize;
  };
  
  int main(){
      const int arrSize = 50;
      Customer custArr[arrSize];
      int i = 0;
      
      //set up file
      ifstream dataFile;
      dataFile.open(&quot;Data.txt&quot;);
         
      //try to open file
      if(!dataFile){
          cout &lt;&lt; &quot;couldn't open file&quot;;
      }
         
      //while dataFile hasn't ended
      while(!dataFile.eof()){
          dataFile.get(custArr[i].name, 21);   
          cout &lt;&lt; custArr[i].name;
          i++;
      }
  }; //end  
  </code></pre>
  <p>I would have thought that the <code>while</code> loop would assign the first 21 characters into <code>custArr[i].name</code>, then loop over and over until the end of file. However, when I print out <code>custArr[i].name</code>, I get this and ONLY this:</p>
  <pre class="lang-none prettyprint-override"><code>Judy Henn           2 Oaklyn Road       Saturday   2001
  </code></pre>
  <p>I'm not sure how to go about assigning a specified number of characters to a variable, while still iterating through the entire file.</p>