title: Indexing issue of C++ string substr function
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/2477850/c-string-substr-function-problem">C++ string.substr() function problem</a>  </p>
  </blockquote>
  
  
  
  <pre><code>string s = "0123456789";
  
  cout&lt;&lt;s.substr(0,4)&lt;&lt;endl;
  
  cout&lt;&lt;s.substr(4,7)&lt;&lt;endl;
  </code></pre>
  
  <p>The output of the above lines of code was pretty unexpected , s.substr(0,4) gave me "0123", s.substr(4,7) gave me "456789" . It was expecting only "456" . Am I missing something here , and is there any alternative to substr function in C++ , which would give me only "456" on the second call. </p>