C++ STL  queue, empty() 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++ empty() for queue to test if the queue is empty or not in C++ programming

To show: How to use the C++ empty() to test if the queue is empty or not in C++ programming

 

// C++ STL queue, empty

#include <queue>

#include <iostream>

using namespace std;

 

int main(void)

{

// declares queues with default deque base container

queue <int> q1, q2;

 

// push an element

q1.push(1);

 

// test for emptiness

if (q1.empty())

cout<<"The queue q1 is empty."<<endl;

else

cout<<"The queue q1 is not empty."<<endl;

if (q2.empty())

cout<<"The queue q2 is empty."<<endl;

else

cout<<"The queue q2 is not empty."<<endl;

return 0;

}

 

Output examples:

 

The queue q1 is not empty.

The queue q2 is empty.

Press any key to continue . . .

 

 

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