iが指す要素を削除し、削除された要素の次の要素を返す反復子を返す
iterator erase(iterator i); |
startからendまでの範囲を指す要素を削除し、削除された要素の次の要素を返す反復子を返す
endが示す要素は削除されない。つまりendが示す反復子が戻り値
iterator erase(iterator start, iterator end); |
#include <iostream> #include <deque> using namespace std; int main() { deque<char> ob; deque<char>::iterator p; int i; for(i=0; i<10; i++) ob.push_back('a' + i); for(i=0; i<ob.size(); i++) cout << ob.at(i) << " " ; cout << "\n要素<" << ob.at(5) << ">削除する。\n"; p = ob.erase(ob.begin() + 5); for(i=0; i<ob.size(); i++) cout << ob.at(i) << " " ; cout << "\n削除された要素の次の要素は<" << *p << ">\n"; ob.erase(ob.begin()+1, ob.end() - 1); for(i=0; i<ob.size(); i++) cout << ob.at(i) << " " ; return 0; } |
実行結果
a b c d e f g h i j 要素<f>削除する。 a b c d e g h i j 削除された要素の次の要素は<g> a j |