Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All


Tests if a stack is empty.

bool empty( ) const;

true if the stack is empty; false if the stack is nonempty.

// stack_empty.cpp
// compile with: /EHsc
#include <stack>
#include <iostream>

int main( )
   using namespace std;
   // Declares stacks with default deque base container
   stack <int> s1, s2;

   s1.push( 1 );

   if ( s1.empty( ) )
      cout << "The stack s1 is empty." << endl;
      cout << "The stack s1 is not empty." << endl;

   if ( s2.empty( ) )
      cout << "The stack s2 is empty." << endl;
      cout << "The stack s2 is not empty." << endl;
The stack s1 is not empty.
The stack s2 is empty.

Header: <stack>

Namespace: std

© 2015 Microsoft