how to delete characters from string in c++ code example
Example 1: remove or erase first and last character of string c++
str.pop_back(); // removes last /back character from str
str.erase(str.begin()); // removes first/front character from str
Example 2: removing a character from a string in c++
#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;
}