C++ reading unknown number of lines and storing values in an array : <p>Firstly I don't really know C++ well at all. Basically I have a file that looks like</p>

<pre><code>junk
junk
...
junk
 3    4    5    1
-9    7    4   -7
 8    6    3    1
....
junk
junk
 7    5    2    -1
....
-1    7    4     1
etc.
</code></pre>

<p>I want to analyze each block of numbers separately. I.e. here I have two blocks of numbers and want to perform the same analysis on them separately.</p>

<p>I know how I would implement this in Python, I just don't know how it looks in C++.</p>

<pre><code>file = open('data.text')
w = []     
x = []
y = []
z = []

for line in file:
  line = line.strip()
  data = line.split()
  w.append(data[0])
  x.append(data[1])
  y.append(data[2])
  z.append(data[3])
file.close()
</code></pre>

<p>I also want to perform an analysis on the block of numbers, comparing all possibilities of two lines at once. In Python it would look something like (I guess -- haven't tried):</p>

<pre><code>r = []
s = []
t = []
for i in range(len(w)):
  for j in range(len(w) - 1):
    r.append(w[i]*x[j] - w[j]*x[i])
    s.append(x[j]*y[i] - y[j]*x[i])

for i in range(len(w):
  for j in range(len(s)):
    t.append(s[j]*w[i] + r[j]*x[i])
best = min(t)
</code></pre>

<p>Here are a couple of the issues I've had in trying this with C++: I do not know the number of rows for the data (call it n), although I do know the number of blocks of numbers I want to analyze (call it N -- in my example N = 2). And plenty of segmentation faults. I think I can store the data, but I can't seem to call it. I create a class Data data and work from there.</p>

<pre><code>double get_data = 0;
for (std::string line; (std::getline(file,line));)
  {
  std::istringstream row(line);
  Data data;
  row &gt;&gt; data.w &gt;&gt; data.x &gt;&gt; data.y &gt;&gt; data.z;

    std::vector&lt;double&gt; wcol;
    std::vector&lt;double&gt; xcol;
    std::vector&lt;double&gt; ycol;
    std::vector&lt;double&gt; zcol;

get_data++;

for (int j = 0; j &lt; get_data - 1; j++) {

  if(data.w &gt; 0)
{

      wcol.push_back(data.w);
      xcol.push_back(data.x);
      ycol.push_back(data.y);
      zcol.push_back(data.z);

     }
get_data = 0;
}
</code></pre>

<p>But again I don't really know what I'm doing with C++.</p>

<hr>

<p>Maybe this should be a separate question, but I'd also like to break out of the analysis and then restart it for the next block of numbers. </p>
