C++ pop_front()
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.
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 elementnumbers.pop_front(); // Removes 10cout << "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:
All contributors
- Anonymous contributor
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve 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