title: How can I read from the same input file multiple times from different points within the file using sentinel values (-1) in c++?
body: <p>I have a task where I have to read different sections of an input file(.txt) of integers in c++.  The file contains an unknown number of positive integers, each separated by white-space with several sentinel values of -1 placed randomly in the list to "break-up" the list into sections and another -1 at the end of the file.</p>
  
  <p>Here is a sample of my input file(.txt):</p>
  
  <pre><code>    3 54 35 4 9 16 -1 14 57 32 4 6 8 41 2 -1 5 6 54 21 3 -1
  </code></pre>
  
  <p>Here is what I've attempted so far:</p>
  
  <pre><code>    int data[20],                       
          index = 0;
  
      ifstream fin;
      fin.open("data_file.txt");
  
      while (index &lt; 20 &amp;&amp; data[index] != -1 &amp;&amp; fin &gt;&gt; data[index])
      {
          cout &lt;&lt; data[index] &lt;&lt; endl;
          index++;
      }
  </code></pre>
  
  <p>I can't get this to read past the first SV even if I repeat this while loop.  It always just starts at the beginning of the file.</p>
  
  <p>How do I read again STARTING AFTER the first SV to the second SV?  The only methods I know involve reading a file from beginning to end.  How do I read seperate sections?</p>
  
  <p>Thanks in advance for any help,
  Cheers</p>