title: Segmentation fault for a particular case
body: <p>I am writing a code which will edit a string.But, my code is giving a segmentation fault for an input "zzzzzzzzzz". I am unable to figure out the reason behind the segmentation fault.</p>
  
  <pre><code>#include&lt;iostream&gt;
  #include&lt;bits/stdc++.h&gt;
  using namespace std;
  int main()
   {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;cin&gt;&gt;t;
  while(t--)
  {
      string s;cin&gt;&gt;s;
      int l=s.size();
      int i=1;
      cout&lt;&lt;l;
      //s.erase(s.begin()+5);
      while(i&lt;(l-1))
      {
          cout&lt;&lt;i&lt;&lt;" ";
          s.erase(s.begin()+i);
          i=i+2;
      }
      cout&lt;&lt;s&lt;&lt;endl;
  }
  //code
  return 0;
  </code></pre>