title: Get the number of elements in a struct array c++
body: <p>I need to find the number of elements in a struct array</p>
  
  <p>I have this struct</p>
  
  <pre><code>struct Features {
      int feature1;
      string feature2;
      string feature3;
      string feature4;
      bool feature5;
  };
  </code></pre>
  
  <p>I have then turned it into an array</p>
  
  <pre><code>Features *feature = new Features[100];
  </code></pre>
  
  <p>I have then entered some values</p>
  
  <pre><code>for(int i = 0; i &lt; 3; i++)
  {
      feature[i].feature1 = 5;
      feature[i].feature2 = "test";
      feature[i].feature3 = "test2";
      feature[i].feature4 = "test3";
      feature[i].feature5 = true;
  }
  </code></pre>
  
  <p>now I want to get the size of the array, which should be 3 (2)</p>
  
  <p>How do I do this?</p>
  
  <pre><code>cout &lt;&lt; (sizeof feature / sizeof *feature) &lt;&lt; endl;
  </code></pre>
  
  <p>doesn't seem to work as it prints the incorrect value. (It keep printing 4)</p>
  
  <p>Sorry if this is a stupid question, I am still learning c++</p>