size_type size() const; |
Returns the number of elements in the underlying container, that is, c.size()
.
(none).
The number of elements in the container.
Constant.
#include <algorithm> #include <iostream> #include <stack> int main() { std::stack<int> container; std::cout << "Initially, container.size(): " << container.size() << '\n'; for (int i = 0; i < 7; ++i) container.push(i); std::cout << "After adding elements, container.size(): " << container.size() << '\n'; }
Output:
Initially, container.size(): 0 After adding elements, container.size(): 7
checks whether the underlying container is empty (public member function) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/w/cpp/container/stack/size