title: results in stopped working when running reverse string program
body: <blockquote>
    <p>I wrote the function to reverse a string in c++ but it results in "stopped working".   </p>
  </blockquote>
  
  <pre><code>#include&lt;iostream&gt;
  #include&lt;string.h&gt;
  using namespace std;
  
  string reverse(string s1)
  {
      string s2;
      for(int i=0;i&lt;s1.length();i++)s2[i]=s1[s1.length()-i-1];
      return s2;
  }
  
  int main()
  {
      string s1,s2;
  
      cin&gt;&gt;s1;
      s2=reverse(s1);
      cout&lt;&lt;s2;
  
  }
  </code></pre>
  
  <blockquote>
    <p>What can be the problem?</p>
  </blockquote>