title: For strings, how do I remove repeated characters?
body: <p>My desired string manipulation procedure: If there is more than one consecutive instance of a character, retain only the first letter. Given "Steelsmith", delete the first "e", leaving the string "Stelsmith".</p>
  
  <p>Here is my algorithim:</p>
  
  <pre><code>void replace(string s)
  {
      int length = s.length();
  
      for (int i = 0; i &lt; length; i ++)
      {
          if (s[i] == s[i + 1])
          {
              s.erase(1+i);
  
          }
  
      }
      cout &lt;&lt; s &lt;&lt; endl;
  }
  </code></pre>
  
  <p>When I input "Steelsmith", the output is "Ste", so it deletes the second 'e', along with the rest of the string. How do I retain the rest of the original string?</p>