title: Function that will act like an Strlen C++
body: <p>I want to make a function that will do the same as Strlen does, andI get the error: "string subscript out of range". I tried fixing it but has no idea.</p>
  
  <p>heres the code:</p>
  
  <pre><code>#include "stdafx.h"
  #include "stdafx.h"
  #include &lt;string&gt;
  #include &lt;sstream&gt;
  #include &lt;iostream&gt;
  
  
  using namespace std;
  
  int strlen1( string str)
  {
      int count=0;
      int i=0;
      while (str[i]!='\0')
          {
              count++;
              i++;
      }
      return count;
  }
  
  int _tmain(int argc, _TCHAR* argv[])
  {
      string input;
      cin &gt;&gt; input;
      cout &lt;&lt; strlen1(input) &lt;&lt; endl;
  
      return 0;
  }
  </code></pre>
  
  <p>thanks!</p>