#include#include using namespace std; int main() { string str = "Hello, world!"; str.erase(5, 7); cout << str << endl; return 0; }
#include#include using namespace std; int main() { string str = "abcdefghij"; str.erase(3); cout << str << endl; return 0; }
#includeOutput: "abcfghij" In this example, the erase function is used to delete 2 characters starting from the 3rd position (index 2) of the string. Package library:#include using namespace std; int main() { string str = "abcdefghij"; str.erase(3, 2); cout << str << endl; return 0; }