Use of string erase function in C++

C++ Use of string erase function

2017年04月05日21:02:17It_BeeCoderReading number: 4286 More
erase function prototype is as follows:
(1)string& erase ( size_t pos = 0, size_t n = npos ); (2) iterator erase ( iterator position ); (3) Iterator erase ( iterator first, iterator last ); that is, there are three uses: (1) erase(pos,n); delete n characters starting from pos, such as erase(0,1) is to delete the first character ( 2) erase(position); delete a character at position (position is a string type iterator) (3) erase(first, last); delete characters from first to last (first and last are iterators) Here's an example for you: 
复制代码
#include <iostream>
#include <string>usingnamespace std; int main () {   string str (This is an example phrase.);   string::iterator it;   //第(1)种使用  str.erase (10,8);   cout << str << endl;        // “This is an phrase.”   //第(2)种使用  it=str.begin()+9;   str.erase (it);   cout << str << endl;        // “This is a phrase.”   //第(3)  str.erase (str.begin()+5, str.end()-7);   cout << str << endl;        // “This phrase.”return0; }