C++ std::queue Functions

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().
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:
#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 functionsLook at the two elements you can see: the oldest one at the front and the newest one at the back.
Capacity
2 functionsCheck if the queue is empty and how many elements it holds.
Modifiers
5 functionsAdd elements at the back, remove the element at the front, or swap two queues.
| Function | Description | Since | Tutorial |
|---|---|---|---|
push() | Add one element at the back of the queue. | C++98 | Try it |
push_range() | Add every element of a range at the back (C++23). | C++23 | Try it |
emplace() | Build a new element right inside the queue, at the back. | C++11 | Try it |
pop() | Remove the front element. It does not return the value. | C++98 | Try it |
swap() | Exchange the contents of two queues of the same type. | C++11 | Try it |
Frequently Asked Questions
Start with back()
Read the newest element, the last one in line, the first function in the alphabetical list.
12 people found this page helpful
