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.
Read More:
- Vector delete pop of element_ back(),erase(),remove()
- C++ foundation — clear/erase/pop of string class_back
- ‘Conversion failed when converting date and/or time from character string.DB-Lib error message 241,
- Java String.split () special character processing
- Error resolution of unexpected token in JSON at position 0
- Unhandled exception at 0x00000000: 0xc0000005: access violation at position 0x0000000000
- Solution: unable to delete folder (you need permission to perform this operation)
- Unexpected token u in JSON at position 0
- Jsoneexception: a jsonobject text must begin with ‘{at character 0
- Illegal escape character in string literal
- Prompt 550 remove directory operation failed when FTP delete folder
- [system]SyntaxError: Unexpected token u in JSON at position 0
- Split keyword in ABAP when the separator is at the beginning and end of the string
- JS error: unexpected token u in JSON at position 0
- Unable to read workspace file ‘D:\angular.json‘: Invalid JSON character: “ “ at
- Error: syntax error – unexpected token P in JSON at position 0
- When MATLAB uses audioread, an error is reported: Error using which Must be a string scalar or character vector.
- JSON data format net.sf.json .JSONException: A JSONObject text must begin with ‘{‘ at character 1 of Error:(f…
- C++ string substr()
- Docker delete error response from daemon: Conflict: unable to delete xxxxx solution