std::basic_string<CharT,Traits,Allocator>::erase (3) - Linux Manuals
std::basic_string<CharT,Traits,Allocator>::erase: std::basic_string<CharT,Traits,Allocator>::erase
NAME
std::basic_string<CharT,Traits,Allocator>::erase - std::basic_string<CharT,Traits,Allocator>::erase
Synopsis
basic_string& erase( size_type index = 0, size_type count = npos ); (1)
iterator erase( iterator position ); (until C++11)
iterator erase( const_iterator position ); (2) (since C++11)
iterator erase( iterator first, iterator last ); (3) (until C++11)
iterator erase( const_iterator first, const_iterator last ); (since C++11)
Removes specified characters from the string.
1) Removes min(count, size()- index) characters starting at index.
2) Removes the character at position.
3) Removes the characters in the range [first, last).
Parameters
index - first character to remove
count - number of characters to remove
position - iterator to the character to remove
first, last - range of the characters to remove
Return value
1) *this
2) iterator pointing to the character immediately following the character erased, or end() if no such character exists
3) iterator pointing to the character last pointed to before the erase, or end() if no such character exists
Exceptions
1) std::out_of_range if index > size().
2-3) (none)
In any case, if an exception is thrown for any reason, this function has no effect (strong exception guarantee).
(since C++11)
Example
// Run this code
Output:
See also
clear (public member function)