1str.pop_back(); // removes last /back character from str
2str.erase(str.begin()); // removes first/front character from str
1#include<iostream>
2#include<algorithm>
3
4using namespace std;
5main() {
6 string my_str = "ABAABACCABA";
7
8 cout << "Initial string: " << my_str << endl;
9
10 my_str.erase(remove(my_str.begin(), my_str.end(), 'A'), my_str.end()); //remove A from string
11 cout << "Final string: " << my_str;
12}
1// string::erase
2#include <iostream>
3#include <string>
4
5int main ()
6{
7 std::string str ("This is an example sentence.");
8 std::cout << str << '\n';
9 // "This is an example sentence."
10 str.erase (10,8); // ^^^^^^^^
11 std::cout << str << '\n';
12 // "This is an sentence."
13 str.erase (str.begin()+9); // ^
14 std::cout << str << '\n';
15 // "This is a sentence."
16 str.erase (str.begin()+5, str.end()-9); // ^^^^^
17 std::cout << str << '\n';
18 // "This sentence."
19 return 0;
20}