String C + + detailed erase find.

Source: Internet
Author: User

Example
12345678910111213141516171819202122
// string::erase#include <iostream>#include <string>using namespace std;int main (){  string str ("This is an example phrase.");  string::iterator it;  // erase used in the same order as described above:
//删除从位置10(从0开始算的,T为第一个位置0)开始的e之后的8个字符"example "
  str.erase (10,8);  cout << str << endl;        // "This is an phrase."
//删除从迭代器开始str.begin()所指的为位置0, +9表示后移9个位置,即指向第十个位置的地址。然后删除该位置的字符 即删除字符n
  it=str.begin()+9;  str.erase (it);  cout << str << endl;        // "This is a phrase."//删除从第五个位置开始即i,到倒数第7个字符即空格之间的字符
  str.erase (str.begin()+5, str.end()-7);  cout << str << endl;        // "This phrase."  return 0;}

String C + + detailed erase find.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.