title: Why use string::iterator rather than index?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/131241/why-use-iterators-instead-of-array-indices">Why use iterators instead of array indices?</a>  </p>
  </blockquote>
  
  
  
  <pre><code>string::iterator it;
  for (it = str.begin(); it &lt; str.end(); it++) 
      cout &lt;&lt; *it;
  cout &lt;&lt; endl;
  </code></pre>
  
  <p>Why not:</p>
  
  <pre><code>for (int i = 0; i &lt; str.size(); i++)
      cout &lt;&lt; str[i];
  cout &lt;&lt; endl;
  </code></pre>
  
  <p>It seems that string::iterator does not provide range check either. Why should we use <code>string::iterator</code> rather than index?</p>
  
  <p>Thanks.</p>