The erase() Function

◀ The rfind() Function▶ getline() versus cin
Amazon The erase() function allows you to remove a sequence of characters from a string. A commonly used function is described as follows:
string & erase(int pos = 0, int n = string::npos);
This function simply erases a sequence of characters from index pos, inclusively, over n characters or until the end of the string, whichever comes first.

Here is one example:
string a = "Michael is not everyone’s friend";
a.erase(11, 4);  /* a is “Michael is everyone’s friend” */
You got that right! I am Michael and I am everybody’s friend!


Next let’s look at how you can get an input from user via the standard input channel!
◀ The rfind() Function▶ getline() versus cin

fShare
Questions? Let me know!