erase() : It remove characters. It returns a reference to this string.
Parameters:
__pos – Index of the first character to remove (default 0).
__n – Number of characters to remove (default remainder).
Syntax:
str.erase(__pos, __n)
For Example:
str = "abcdef"
str.erase(1,3) => It removes 3 characters from position 1. So, string becomes "aef"
Approach
C++
#include <bits/stdc++.h>using namespace std;int main(){string str = "abcdef";str.erase(1, 3);cout << str << "\n";return 0;}
No comments:
Post a Comment