English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

C++ Usage and examples of pop_back() function

C++ List (List)

C ++ The pop_back() function of List removes the last element from the list and reduces the size of the list by one.

The pop_back() function deletes the last element, that is4

Syntax

void pop_back();

Parameters

It does not contain any parameters.

Return value

It does not return any value.

Example

Let's look at a simple example

#include <iostream>  
#include<list>  
using namespace std;  
int main()
{
   list li={6,7,8,9};
   list::iterator itr;
   li.pop_back();
   li.pop_back();
  for(itr=li.begin();itr!=li.end();++itr){
      cout<<*itr<<",";
  }
  
  return 0;
}

Output:

6,7

In this example, the pop_back() function removes the last two elements from the list.

C++ List (List)