C++ STL  queue, pop() 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++ pop() for queue to remove an element from the front of the queue in C++ programming

To show: How to use the C++ queue, pop() to remove an element from the front of the queue in C++ programming

 

// C++ STL queue, pop()

#include <queue>

#include <iostream>

using namespace std;

 

int main(void)

{

queue <int> que;

 

// push/insert data

que.push(21);

que.push(9);

que.push(13);

 

queue <int>::size_type i;

i = que.size();

 

// print the data

cout<<"The queue length is "<<i<<endl;

i = que.front();

cout<<"The element at the front of the queue is "<<i<<endl;

// do the popping

que.pop();

i = que.size();

cout<<"After a pop the queue length is "<<i<<endl;

i = que.front();

cout<<"After a pop, the element at the front of the queue is "<<i<<endl;

return 0;

}

 

Output examples:

 

The queue length is 3

The element at the front of the queue is 21

After a pop the queue length is 2

After a pop, the element at the front of the queue is 9

Press any key to continue . . .

 

 

C and C++ Programming Resources | C & C++ Code Example Index