title: Select specific data in text file to import in 2d array in c++
body: <p>I am new to C++ programming and I am trying to open a text file where most of the information isn't useful to me. The file looks like that:</p>
  <blockquote>
  <p>1</p>
  <p>547</p>
  <p>troncons</p>
  <p>0 1 2 ...</p>
  <p>2 2 3 4 5 7 ...</p>
  <p>0 4 5 ...</p>
  <p>...</p>
  </blockquote>
  <p>So as you can see each line has a different length. What I want to extract first is the second element (547) which tell me the number of line after &quot;troncons&quot;. After that, the number in the first column tell me how the information is distributed in the line so if it's 0, that means the second value is x and the third is y, but if the first value isn't 0 then the second value is x, the third is the number n of y values and the n next value are the y associated to the x. I'm only working with integer and I am trying to create an array of dimension (i,2) where each line is a (x,y) couple. Also there are other values at the end of each, but I don't need it.</p>
  <p>I got an idea on how my code should work, but I don't know how to write it in C++ since I'm used to Matlab</p>
  <blockquote>
  <ol>
  <li><p>get the number of line either by extracting the value in the second line or by getting the total number of line and subtracting 3.</p>
  </li>
  <li><p>Iterate on each line and use a conditional statement to know if the first element is 0 or not.</p>
  </li>
  <li><p>Then if it's 0, add  the second and the third value to the array.</p>
  </li>
  <li><p>If it is !=0, get the third value and iterate over that number to add in the array the x from the second value and the y from the 3+i value.</p>
  </li>
  </ol>
  </blockquote>
  <p>That's how I did it in Matlab because they automatically put the text in a matrix and it is easy to access it with index, but I feel you can't do that with C++.</p>
  <p>I saw those two links:
  <a href="https://stackoverflow.com/questions/8913394/how-do-i-read-an-entire-txt-file-of-varying-length-into-an-array-using-c?rq=1">How do i read an entire .txt file of varying length into an array using c++?</a></p>
  <p><a href="https://stackoverflow.com/questions/15588800/reading-matrix-from-a-text-file-to-2d-integer-array-c">Reading matrix from a text file to 2D integer array C++</a></p>
  <p>But the first one used a vector or a one dimensonal array and the second one took all the information directly and used static memory.</p>