title: Initializing a vector every loop
body: <p>When I declare a vector, it is by default padded to zero. As a part of a simulation I would like it to initialize every iteration in a loop. what is the correct and efficient way to do it?</p>
  
  <p>I would like to address two cases:</p>
  
  <ol>
  <li><p>I would like it to be zeroed to a known value, i.e nSteps</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  using namespace std;
  const int nSteps = 10000;
  const int nReal = 10;
  int main()
  {
      for (unsigned int i = 0 ; i&lt;nRealization; i++)
      {
          vector&lt;double&gt; v(nSteps);
          for (unsigned int j = 0 ; j&lt;nSteps ;  j++)
          {
              //stuff going on with v
          }
      }
  }
  </code></pre></li>
  <li><p>The length is not defined ( it is given with a function that uses <code>push_back</code> )</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  
  using namespace std;
  const int nSteps = 10000;
  const int nReal = 10;
  int main()
  {
      for (unsigned int i = 0 ; i&lt;nRealization; i++)
      {
          vector&lt;double&gt; v;
          // some function that uses push_back gives v its length
  
          for (unsigned int j = 0 ; j&lt;nSteps ;  j++)
          {
  
              //stuff going on with v
          }
      }
  }
  </code></pre></li>
  </ol>