Using iterator and erase
Here, we use a function erase (iterator) of string to delete the characters at the specified position. The iterator iterator can string.begin () get the first iterator of the string, and then add different values to delete it.
string s = "abcdefg";
int i = 3;
string::iterator itr = s.begin();
itr+=i;
s.erase(itr);
s.erase(itr);
cout<<s;
Here we want to delete “de”. Because we get the first iterator and add the value, we delete “d”. If we want to delete “e”, we don’t need to add any value, because the position of “e” is just “d”, so we just need to erase () again.