English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
C ++ The Queue front() function returns the first element of the queue. The first element is the earliest element or the element added to the queue first. This function is used to return this element.
value_type& front(); const value_type& front() const;
This function does not take any parameters and is used only to return the value of the first element in the queue.
This function returns the front element of the queue.
#include <iostream> #include <queue> int main() { std::queue<int> newqueue; newqueue.push(24); newqueue.push(80); newqueue.front()() +=20; std::cout << "newqueue.front() modify to " << newqueue.front(); return 0; }
Output:
Modify newqueue.front() to 44
#include <iostream> #include <queue> using namespace std; int main() { queue<int> newqueue; newqueue.push(11); newqueue.push(22); newqueue.push(33); cout << newqueue.front(); return 0; }
Output:
11
The complexity of the function is constant.
This function accesses the container. It accesses the queue container entirely and then returns the earliest element.
Guarantees operations equivalent to those performed on underlying container objects.