stack::empty

;如果堆栈为空,测试。

bool empty( ) const;

返回值

true ;如果堆栈为空; false,如果堆栈非空。

示例

// 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;
   else
      cout << "The stack s1 is not empty." << endl;

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

要求

标头: <stack>

命名空间: std

请参见

参考

stack Class

stack::top 和 stack::empty

标准模板库