c++ strings(字符串) 成员 erase():删除字符
删除(erase)
语法:
iterator erase( iterator pos );
iterator erase( iterator start, iterator end );
basic_string &erase;( size_type index = 0, size_type num = npos );
|
erase()函数可以:
参数index 和
num 有默认值, 这意味着erase()可以这样调用:只带有
index以删除index后的所有字符,或者不带有任何参数以删除所有字符. 例如:
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, 14 );
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 ''