共用方式為


stack::size

Returns the number of elements in the stack.

size_type size( ) const;

Return Value

The current length of the stack.

Example

// 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;
}
The stack length is 1.
The stack length is now 2.

Requirements

Header: <stack>

Namespace: std

See Also

Reference

stack Class

stack::size (STL Samples)

Standard Template Library