簡述
描述
重新初始化固定大小數組的元素,并釋放動态數組的存儲空間。
語法
iterator erase( iterator pos );
iterator erase( iterator start, iterator end );
basic_string &erase( size_type index = 0, size_type num = npos );
删除pos指向的字符, 返回指向下一個字符的叠代器;
删除從start到end的所有字符, 返回一個叠代器,指向被删除的最後一個字符的下一個位置;
删除從index索引開始的num個字符, 返回*this;
參數index 和 num 有默認值, 這意味着erase()可以這樣調用:隻帶有index以删除index後的所有字符,或者不帶有任何參數以删除所有字符。
參數
First
An iterator addressing the position of the first element in the range to be erased.
Last
An iterator addressing the position one past the last element in the range to be erased.
It
An iterator addressing the position of the element in the string to be erased.
Pos
The index of the first character in the string to be removed.
Count
The number of elements that will be removed if there are as many in the range of the string beginning with _Pos.
返回值
For the first two member functions, an iterator addressing the first character after the last character removed by the member function. For the third member function, a reference to the string object from which the elements have been erased.