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 ()