The erase string () function

erase () is a function string to a string to delete operation element

 

 

1, erase (int index) delete the index index from the beginning until the end of the string element

1 string s = "1232157"; 2 s.erase(3); 3 cout << s;//123

 

2, erase (int index, int num) num elements deleted from the index subscript beginning

string s = "1234567";
s.erase(3,2);
cout << s;//12367

 

. 3, ERASE (IT Iterator :: String) iterator to remove elements, the function's return value is an iterator to point the next element of the removed element

 string::iterator it;
 string s = "1234567";
 it=s.erase(s.begin()+1);
 cout << s << endl;//134567
 cout << *it;//3

4, erase (string :: iterator it1, string :: iterator it2) to remove elements [it1, it2) of the region, the return value of the function is an iterator to point the next element of the removed element

string::iterator it;
string s = "1234567";
it=s.erase(s.begin()+1,s.end()-1);
cout << s << endl;//17
cout << *it;//7

 

Guess you like

Origin www.cnblogs.com/program-ai-cv-ml-se-fighting/p/11921435.html