title: Using auto in loops c++
body: <p>I get warning signed/unsigned mismatch for the following code:</p>
  
  <pre><code>auto n = a.size();
  for (auto i = 0; i &lt; n; i++) {
  }
  </code></pre>
  
  <p>The problem is that by assigning 0 to <code>i</code> it becomes <code>int</code> rather than <code>size_t</code>.
  So what is better:</p>
  
  <pre><code>size_t n = a.size();
  for (size_t i = 0; i &lt; n; i++) {
  }
  </code></pre>
  
  <p>or this:</p>
  
  <pre><code>auto n = a.size();
  for (size_t i = 0; i &lt; n; i++) {
  }
  </code></pre>
  
  <p>or maybe you have a better solution? I like the first one more because
  it is bit more consistent, it just uses <code>size_t</code> rather than both <code>size_t</code> and <code>auto</code>
  for the same purpose.</p>