The characters affected depend on the member function version used:
- string& erase ( size_t pos = 0, size_t n = npos );
- Erases a sequence of n characters starting at position pos. Notice that both parameters are optional: with only one argument, the function deletes everything from position pos forwards, and with no arguments, the function deletes the entire string, like member clear.
- iterator erase ( iterator position );
- Erases the character referred by the iterator position. Only one character is affected.
- iterator erase ( iterator first, iterator last );
- Erases all the characters between first and last.
Parameters
- pos
- Position within the string of the first character to be erased.
If the position passed is past the end of the string, an out_of_range exception is thrown.
- n
- Amount of characters to be removed. It may remove less characters if the end of the string is reached before the n characters have been erased. The default value of npos indicates that all the characters until the end of the string should be erased.
size_t is an unsigned integral type. - position
- Iterator of the member type string::iterator referring to a single character in the string to be removed.
- first
- Iterator of the member type string::iterator referring to the first character in a sequence of characters within the string to be erased.
- last
- Iterator of the member type string::iterator referring to the last character in the sequence of characters within the string to be erased.
Return Value
For the member that returns a string&, the function returns *this.For the remaining members, the function returns an iterator of member type string::iterator referring to the character that now occupies the position of the first character erased, or, if no such character exists, returns end().
Example
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
Basic template member declaration
( basic_string<charT,traits,Allocator> )| 1 2 3 4 |
|
See also
| string::clear | Clear string (public member function) |
| string::replace | Replace part of string (public member function) |
| string::insert | Insert into string (public member function) |
| string::assign | Assign content to string (public member function) |
