GeezerVison is showing cpprefjp.github.io — std::basic_string::erase - cpprefjp C++日本語リファレンス
最終更新日時:
2026年10月03日 22時31分04秒 (JST)
Akira Takahashi
が更新
履歴
編集
function
<string>
std:: basic_string:: erase
basic_string &
erase ( size_type pos = 0 , size_type n = npos ); // (1) C++98
constexpr basic_string &
erase ( size_type pos = 0 , size_type n = npos ); // (1) C++20
iterator erase ( iterator p ); // (2) C++98
iterator erase ( const_iterator p ); // (2) C++11
constexpr iterator erase ( const_iterator p ); // (2) C++20
iterator
erase ( iterator first ,
iterator last ); // (3) C++98
iterator
erase ( const_iterator first ,
const_iterator last ); // (3) C++11
constexpr iterator
erase ( const_iterator first ,
const_iterator last ); // (3) C++20
概要
要素を削除する。
(1) : pos番目からn要素を削除する。
(2) : イテレータpが指す要素を削除する
(3) : イテレータ範囲[first, last)を削除する
要件
(1) : pos <= size()
(3) : firstとlastが*thisに対する有効なイテレータであり、[first, last)が有効な範囲であること。
効果
(1) : nとsize() - posのうち小さい方をxlenとし、pos番目からxlen個の要素を削除する。
(2) : イテレータpが指す要素を削除する。
(3) : イテレータ範囲[first, last)の文字列を削除する。
戻り値
(1) : *this
(2) : 削除した要素の次を指すイテレータを返す。そのような要素がなければend() を返す。
(3) : 最後に削除した要素の次を指すイテレータを返す。そのような要素がなければend() を返す。
例外
例
出力
(1) : 145
(2) : 1245
(3) : 12
参照