C++ STL queue, front() program example
Compiler: Visual C++ Express Edition 2005
Compiled on Platform: Windows XP Pro SP2
Header file: Standard
Additional project setting: Set project to be compiled as C++
Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C++ Code (/TP)
Other info:
To do: Using the C++ front() to return a reference to the first element at the front of the queue in C++ programming
To show: How to use the C++ queue, front() to return a reference to the first element at the front of the queue in C++ programming
// C++ STL queue, front()
#include <queue>
#include <iostream>
using namespace std;
int main(void)
{
queue <int> que;
// insert/push data
que.push(9);
que.push(12);
que.push(20);
que.push(15);
queue <int>::size_type x;
x = que.size();
// print the data
cout<<"The queue length is "<<x<<endl;
// y hold an address of back
int &y = que.back();
// y hold an address of front
int &z = que.front();
// print the data
cout<<"The integer at the back of queue que is "<<y<<endl;
cout<<"The integer at the front of queue que is "<<z<<endl;
return 0;
}
Output examples:
The queue length is 4
The integer at the back of queue que is 15
The integer at the front of queue que is 9
Press any key to continue . . .