C++ STL  queue, the push() 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++ push() for queue to add an element to the back of the queue in C++ programming

To show: How to use the C++ push()  for queue to add an element to the back of the queue in C++ programming

 

// C++ STL queue, push()

#include <queue>

#include <iostream>

using namespace std;

 

int main(void)

{

queue <int> que;

 

// push/insert data into queue

que.push(23);

que.push(15);

que.push(32);

 

queue <int>::size_type i;

i = que.size();

 

// print some info

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

i = que.front();

cout<<"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 23

Press any key to continue . . .

 

 

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