Syntax:
#include <string> iterator erase( iterator loc ); iterator erase( iterator start, iterator end ); basic_string& erase( size_type index = 0, size_type num = npos );
eraase()関数は、次の動作をします。
The parameters index and num have default values, which means that erase() can be called with just index to erase all characters after index or with no arguments to erase all characters.
パラメータの “index” と “num” はデフォルトの値を持っています。そのため、erase()関数を引数なしで呼び出すとすべての文字列を削除します。
例)
string s("So, you like donuts, eh? Well, have all the donuts in the world!"); cout << "The original string is '" << s << "'" << endl; s.erase( 50, 13 ); cout << "Now the string is '" << s << "'" << endl; s.erase( 24 ); cout << "Now the string is '" << s << "'" << endl; s.erase(); cout << "Now the string is '" << s << "'" << endl;
出力
The original string is 'So, you like donuts, eh? Well, have all the donuts in the world!' Now the string is 'So, you like donuts, eh? Well, have all the donuts!' Now the string is 'So, you like donuts, eh?' Now the string is ''
erase() は線形時間で実行されます。
Related Topics: insert