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.
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;cin>>t;
while(t--)
{
string s;cin>>s;
int l=s.size();
int i=1;
cout<<l;
//s.erase(s.begin()+5);
while(i<(l-1))
{
cout<<i<<" ";
s.erase(s.begin()+i);
i=i+2;
}
cout<<s<<endl;
}
//code
return 0;