다음을 통해 공유


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)

표준 템플릿 라이브러리