Delete (erase)
Syntax:
IteratorErase (IteratorPos );IteratorErase (IteratorStart,IteratorEnd); basic_string & erase (size_type Index = 0, size_type num = NPOs ); |
The erase () function can be:
- Delete the characters pointed to by POS, and returnIterator,
- Delete all characters from start to end, ReturnsIterator, Pointing to the next position of the last character to be deleted
- Delete num characters starting from Index, Return* This.
ParametersIndexAndNumThere is a default value, which means that erase () can be called as follows:IndexTo delete all characters after the index, or to delete all characters without any parameters. For example:
String S ("so, you like donuts, eh? Well, have all the donuts in the world! "); Cout <" the original string is '"<S <"' "<Endl; S. erase (50, 14); cout <"Now the string is '" <S <"'" <Endl; S. erase (24); cout <"Now the string is '" <S <"'" <Endl; S. erase (); cout <"Now the string is '" <S <"'" <Endl;
Will display
The original string is 'So, you like donuts, eh? Well, have all the donuts in the world! 'Now the string is 'So, you like donuts, eh? Well, have all the donuts 'Now the string is 'So, you like donuts, eh? 'Now the string is''