title: about strings in c++
body: <p>This is the code for removing consecutive  words:</p>
  
  <pre><code>std::string unstretch(std::string word)
  {
      std::string s;
      int k=0;
  
      for(int i=0;i&lt;word.length();k++,i++)
      {
          if(word[i]!=word[i+1])
          {
              s[k]=word[i];
          }
          else
              k--;
      }
      s[k]='\0';
      return s;
  }
  </code></pre>
  
  <p>This code works if we replace <code>string s</code> with <code>char s[50]</code>. Can someone explain why this happens?</p>