This function is included in the "boost/algorithm/string" library. This library contains some brilliant methods which help in accomplishing string manipulations that are lacking in STL library.
This function is used to remove the tail of the input string. It first identifies the tail by taking last N characters , where N is given by the user. It then proceeds to remove the tail of the input string.
input_string : an input string
N : An integer which specifies the number of characters to be considered as tail
(For N>=0, at most N characters are extracted. For N<0, size(Input)-|N| characters are extracted.)
erase_tail() performs an inplace removal. There is another variation present erase_tail_copy() which instead of doing an inplace removal, returns a copy of the modified string.
using namespace std;
using namespace boost::algorithm;
string str1 = "Hello and Welcome to Boost";
string str2 = "Apple Banana Mango Apple Banana Apple";
string str4 = "Hi Hi Hi Hi Hi Hi";
string str3 = erase_tail_copy(str4,3);
As we can observe from the output we are first performing an inplace removal where we are removing the last 5 characters of the input string i.e., "Boost". In str3, we are storing the copy of the modified string i.e., inplace removal is not preformed.