std::stack<T,Container>::size
From cppreference.com
size_type size() const; |
||
Returns the number of elements in the underlying container, that is, c.size().
Contents |
[edit] Parameters
(none)
[edit] Return value
The number of elements in the container adaptor.
[edit] Complexity
Constant.
[edit] Example
Run this code
#include <algorithm> #include <iostream> #include <stack> int main() { std::stack<int> stack; std::cout << "Initially, stack.size(): " << stack.size() << '\n'; for (int i = 0; i < 8; ++i) stack.push(i); std::cout << "After adding elements, stack.size(): " << stack.size() << '\n'; }
Output:
Initially, stack.size(): 0 After adding elements, stack.size(): 8
[edit] See also
checks whether the container adaptor is empty (public member function) | |
(C++17)(C++20) |
returns the size of a container or array (function template) |