C++ queue back() Function
Example
Get the last element of a queue:
queue<string> cars;
cars.push("Volvo");
cars.push("BMW");
cars.push("Ford");
cars.push("Mazda");
cout << cars.back();
Definition and Usage
The back() function returns the last element of a queue. This is the element that was added last.
You can also use it to change the last element, like cars.back() = "VW";.
The back function is defined in the <queue> header file.
Syntax
queue.back();
Parameter Values
None.
Technical Details
| Returns: | A reference to the last element of the queue. |
|---|
Related Pages
Read more about queues in our Queues Tutorial.