title: Reading first X characters of a line to a string
body: <p>I have a file that is formatted like this:</p>
  
  <pre><code>Word1          num1 num2
  Word2 Word3    num3 num4
  </code></pre>
  
  <p>between Word1 and num1 there are 15 spaces, which are used by words like Word1, Word2 and Word3.</p>
  
  <p>I want to read the first 15 characters and put them into a string, then read the numbers:</p>
  
  <pre><code>string[0] = "Word1          ";
  number[0] = num1;
  number[1] = num2;
  string[1] = "Word2 Word3    ";
  number[2] = num3;
  number[3] = num4;
  ...
  </code></pre>
  
  <p>The function i currently use to read the data from the file:</p>
  
  <pre><code>void read_data(){
  
  ifstream datafile("U2.txt");
  
  datafile&gt;&gt; product_count &gt;&gt; product2_count;
  
  for (int i = 1; i &lt;= product_count; i++) {
      datafile&gt;&gt; product_cost[i];
  }
  
  for (int i = 1; i &lt;= product2_count; i++) {
      datafile&gt;&gt; products[i].product2_name;
      for (int j = 1; j &lt;= product_count; j++) {
          datafile&gt;&gt; products[i].product_ammount[j];
      }
  }
  
  datafile.close();
  
  }
  </code></pre>
  
  <p>and the data file itself:</p>
  
  <pre><code>6 5
  12 25 35 2 3 9
  Salotos        5 1 0 0 2 1
  Kepsnys        6 3 12 9 0 0
  Gaiva          0 0 1 15 1 0
  Ledai Miau     0 0 5 5 5 1
  Tortas         1 2 1 1 1 1
  </code></pre>