xxxxxxxxxx
#include<bits/stdc++.h>
using namespace std;
int main(){
string c = "computer";
cout << c.erase(2,1) << "\n";
// erase(2,1); here 2 is the index where the erase function will start to erase. 1 is the number of items it will remove. If you don't specify it, erase function will erase everything after the index 2.
xxxxxxxxxx
#include<iostream>
#include<algorithm>
using namespace std;
main() {
string my_str = "ABAABACCABA";
cout << "Initial string: " << my_str << endl;
my_str.erase(remove(my_str.begin(), my_str.end(), 'A'), my_str.end()); //remove A from string
cout << "Final string: " << my_str;
}
xxxxxxxxxx
#include <algorithm>
str.erase(std::remove(str.begin(), str.end(), 'a'), str.end());
xxxxxxxxxx
static void StrRemoveChar(std::string& s1, char l)
{
s1.erase(std::remove(s1.begin(), s1.end(), l), s1.end());
}
xxxxxxxxxx
nclude<iostream>
#include<algorithm>
using namespace std;
main() {
string my_str = "ABAABACCABA";
cout << "Initial string: " << my_str << endl;
my_str.erase(remove(my_str.begin(), my_str.end(), 'A'), my_str.end()); //remove A from string
cout << "Final string: " << my_str;