C++ std::queue Functions

Beginner
8 min read
Updated: Nov 2026
9 function guides
Function index

About This Index

This page is the C++ std::queue Functions index. Each row links to a full guide with syntax, parameters, return value, three examples, and FAQs.

Learn what a queue is on /cpp/queue. Use this page when you need a specific function such as push(), front(), or pop().

Member functions of a container adaptor.

std::queue lives in the <queue> header. You call its functions with a dot, such as q.push(5). It is first in, first out (FIFO): new elements join at the back and leave from the front. You can only see those two ends. There is no iterator and no []. The 9 functions are listed below with the C++ version each one needs.

How to Call a queue Function

Include <queue>, create a queue, and call the functions on it:

C++
#include <queue>
#include <iostream>
#include <vector>

std::queue<int> q;                        // FIFO: first in, first out

q.push(10);                                       // join at the back
q.push(40);
q.emplace(20);                                    // build in place (C++11)
int oldest = q.front();                           // 10, the next to leave
int newest = q.back();                            // 20, the last to leave
std::size_t n = q.size();                         // 3
bool none = q.empty();                            // false
q.pop();                                          // remove 10, returns nothing

std::vector<int> more = {5, 6};
q.push_range(more);                               // C++23 only

C++ std::queue Functions Table

All function guides in this C++ tutorial series (9 tutorials), grouped by purpose.

Element access

2 functions

Look at the two elements you can see: the oldest one at the front and the newest one at the back.

FunctionDescriptionSinceTutorial
front()Read the oldest element, the next one that will leave the queue.C++98Try it
back()Read the newest element, the last one in line.C++98Try it

Capacity

2 functions

Check if the queue is empty and how many elements it holds.

FunctionDescriptionSinceTutorial
empty()Check if the queue has no elements. It returns true or false.C++98Try it
size()Count how many elements are waiting in the queue.C++98Try it

Modifiers

5 functions

Add elements at the back, remove the element at the front, or swap two queues.

FunctionDescriptionSinceTutorial
push()Add one element at the back of the queue.C++98Try it
push_range()Add every element of a range at the back (C++23).C++23Try it
emplace()Build a new element right inside the queue, at the back.C++11Try it
pop()Remove the front element. It does not return the value.C++98Try it
swap()Exchange the contents of two queues of the same type.C++11Try it

Frequently Asked Questions

std::queue has a small set of member functions: front() and back() to read the two ends, empty() and size() to check capacity, and push(), push_range() (C++23), emplace() (C++11), pop(), and swap() (C++11) to change the queue.
This series covers 9 functions, grouped as element access (front, back), capacity (empty, size), and modifiers (push, push_range, emplace, pop, swap).
emplace() and swap() need C++11. push_range() needs C++23. The functions front(), back(), empty(), size(), push(), and pop() work in every C++ standard.
A queue is a container adaptor that only lets you see the two ends: front() and back(). It has no iterators and no random access. To visit every element you must use front() and pop() in a loop until empty() is true.
Read the C++ queue page first. Then open push(), front(), and pop() from the tables below, because those three are used in almost every program that has a queue.

Start with back()

Read the newest element, the last one in line, the first function in the alphabetical list.

back() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful