pop_back() Method is used to remove an element from the end of a List.
Let us say, we have a List that contains three names, Mohan, Kriti and Salim. And we want to remove Salim from the List.
It can be done with the pop_front() Method
#include <iostream>
#include <list>
using namespace std;
int main() {
list<string> x = {"Mohan", "Kriti", "Salim"};
x.pop_back();
for (string data : x)
{
cout << data << endl;
}
return 0;
}
So, in the above code we have created a List and initialised to the variable x.
list<string> x = {"Mohan", "Kriti", "Salim"};Below is how the values are positioned in the List,
-Method1.png)
Next, we have used the pop_front() method that searches for the first element(And the first element is Mohan) and removes it from the List.
x.pop_back();
-Method2.png)