String. Erase ()

Source: Internet
Author: User

To implement this function in the code, remove the brackets of the string stored in string [00000001]. The first thing that comes to mind is the string. Erase () function. Result...

Code:

 1 #include <iostream> 2 #include <string> 3  4 using namespace std; 5  6 void strSize() 7 { 8     string strTest = "[0000-0001]"; 9     strTest.erase(strTest.size() - 1);10     strTest.erase(0);11 }12 13 void strLength()14 {15     string strTest = "[0000-0001]";16     strTest.erase(strTest.length() - 1);17     strTest.erase(0);18 19     cout << strTest << endl;20 }21 22 void strIterator()23 {24     string strTest = "[0000-0001]";25     strTest.erase(strTest.begin());26     strTest.erase(strTest.end() - 1);27 }28 29 int main(int argc, char *argv)30 {31     strIterator();32 33     return 0;34 }

This Code contains three functions for test, but only one is available, striterator

The other two always prompt a segment error. In addition, tracing debugging finds that after erase is used, the size of strtest is changed to 0.

After that, you have enough knowledge to solve the problem.

Come on, boy!

 

String. Erase ()

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.