stack::size

返回的元素数目在堆栈中。

size_type size( ) const;

返回值

当前堆栈的长度。

示例

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

int main( )
{
   using namespace std;
   stack <int> s1, s2;
   stack <int>::size_type i;

   s1.push( 1 );
   i = s1.size( );
   cout << "The stack length is " << i << "." << endl;

   s1.push( 2 );
   i = s1.size( );
   cout << "The stack length is now " << i << "." << endl;
}
  

要求

页眉: <堆栈>

命名空间: std

请参见

参考

stack 类

stack::size(STL 示例)

标准模板库