std::stack<T,Container>::size - cppreference.com
来自cppreference.com
返回容器适配器中的元素数,等价于:return c.size()。
返回值
容器适配器中的元素数。
复杂度
常数。
示例
#include <cassert> #include <stack> int main() { std::stack<int> stack; assert(stack.size() == 0); const int count = 8; for (int i = 0; i != count; ++i) stack.push(i); assert(stack.size() == count); }