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;
}
  
  

要求

标头: <stack>

命名空间: std

请参见

参考

stack Class

stack::size (STL Samples)

标准模板库