The erase function is prototype as follows:
(1) string & erase (size_t Pos = 0, size_t n = NPOs );
(2) iterator erase (iterator position );
(3) iterator erase (iterator first, iterator last );
That is to say, there are three usage methods:
(1) Erase (Pos, n); Delete n characters starting from pos. For example, erase (0, 1) is to delete the first character.
(2) Erase (position); delete a character at position (position is a string type iterator)
(3) Erase (first, last); Delete the characters from first to last (both first and last are iterators)
Here is an example:
// String: erase # include <iostream> # include <string> using namespace STD; int main () {string STR ("this is an example phrase. "); string: iterator it; // Str. erase (10, 8); cout <STR <Endl; // "This Is An phrase. "// It = Str. begin () + 9; Str. erase (it); cout <STR <Endl; // "this is a phrase. "// Str. erase (Str. begin () + 5, str. end ()-7); cout <STR <Endl; // "this phrase. "Return 0 ;}