C++ pop_front()

Anonymous contributor's avatar
Anonymous contributor
Published Oct 22, 2025
Contribute to Docs

The pop_front() method in C++ deque removes or pops the first (front) element from the deque, reducing its size by one.

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn C++ — a versatile programming language that’s important for developing software, games, databases, and more.
    • Beginner Friendly.
      11 hours

Syntax

deque_name.pop_front();

Parameters:

This method does not take any parameters.

Return value:

pop_front() does not return anything and removes the first element from the deque

Example

In this example, the first element of an integer deque is removed, and the updated deque is printed:

#include <iostream>
#include <deque>
using namespace std;
int main() {
deque<int> numbers = {10, 20, 30, 40};
// Remove the first element
numbers.pop_front(); // Removes 10
cout << "Deque after pop_front(): ";
for (int num : numbers) {
cout << num << " ";
}
return 0;
}

The output of this code is:

Deque after pop_front(): 20 30 40

Codebyte Example

In this example, the first element of a string deque is removed, and the new front element is displayed:

Code
Output
Loading...

All contributors

Contribute to Docs

Learn C++ on Codecademy

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn C++ — a versatile programming language that’s important for developing software, games, databases, and more.
    • Beginner Friendly.
      11 hours