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

C++ Deque pop_front() Usage and Example

C++ Deque (Double-ended Queue)

C ++ The Deque pop_front() function removes the first element from the deque and the container size decreases by one.

Syntax

void pop_front();

Parameters

It does not contain any parameters.

Return value

It does not return any value.

Example1

Let's look at a simple example

#include iostream>
#include<deque>
using namespace std;
int main()
{
    deque<int> d={10,20,30,40,50};
    deque<int>::iterator itr;
    d.pop_front();
    for(itr=d.begin();itr!=d.end();++itr)
    cout <<*itr << " ";
    return 0;
  }

Output:

20 30 40 50

In this example, the pop_front() function removes the first element from the deque (i.e.,10)

Example2

Let's look at a simple example

#include iostream>
#include<deque>
using namespace std;
int main()
{
    deque<string> language={"C","C"}++"", "java", ".net"};
    deque<string>::iterator itr;
    language.pop_front();
    for(itr = language.begin(); itr != language.end();++itr)
    cout <<*itr << " ";
    return 0;
 }

Output:

C++ java.net

In this example, the pop_front() function removes the first string from the deque, that is, 'C'.

C++ Deque (Double-ended Queue)