title: Get index of the struct array which holds the smallest value
body: <p>Edit: I appreciate the answers very much!</p>
  
  <p>So imagine we have a struct like this</p>
  
  <pre><code>struct BadQuestion
  {
     float a;
     float b;
  
  } BadArray[10];
  </code></pre>
  
  <p>On a typical day <code>float a</code> will look like following</p>
  
  <pre><code>{ 0, 152.52, 25.26, 5.166, 263.25, 256.256, 452.25, 0, 0, 0 }
  </code></pre>
  
  <p>Now I need to find the smallest value (5.166) and get the index of that in the array (which would be 3) because later I will need to extract <code>float b</code> from <code>BadArray[3]</code>.</p>
  
  <p>I do not want to include the 0 values in the search, of course. And what I've tired is adding all non-0 values to a vector then use <code>min_element</code> to get the lowest value of <code>float a</code>. Problem is that I don't know how to get the index.</p>
  
  <p><strong>Current code</strong></p>
  
  <pre><code>vector&lt;float&gt; temp;
  int size = 0;
  for (int i = 0; i &lt; 10; i++)
  {
      if (BadArray[i].a != 0) {
          temp.push_back(BadArray[i].a);
          size++;
      }
  }
  
  auto entity = min_element(temp.begin(), temp.end());
  </code></pre>