Delete (erase)

Source: Internet
Author: User

Delete (erase)

Syntax:

IteratorErase (IteratorPos );IteratorErase (IteratorStart,IteratorEnd); basic_string & erase (size_type Index = 0, size_type num = NPOs );

The erase () function can be:

    • Delete the characters pointed to by POS, and returnIterator,
    • Delete all characters from start to end, ReturnsIterator, Pointing to the next position of the last character to be deleted
    • Delete num characters starting from Index, Return* This.

ParametersIndexAndNumThere is a default value, which means that erase () can be called as follows:IndexTo delete all characters after the index, or to delete all characters without any parameters. For example:

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;

Will display

 
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''

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.