title: Can you avoid out of range error if you use range based for loop instead of the standard for loop?
body: <p>I was experimenting around with <strong>range-based</strong> for loop found that if you use range-based for loop to loop through a vector it runs into <strong>out of range</strong> error is there any way to avoid this error if you are using <strong>range-based</strong> for loop</p>
  <pre><code>int main()
  {
      vector&lt;int&gt; num{ 1,2,3,4,5 };
      for (auto i : num)
      {
          cout &lt;&lt; num[i] &lt;&lt; endl;
      }
  }
  </code></pre>
  <p>it shows this error</p>
  <p><a href="https://i.stack.imgur.com/sCs4m.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sCs4m.png" alt="enter image description here" /></a></p>