最終更新日時(UTC): 2025年07月11日 17時16分44秒 Koichi Murase が更新
履歴 編集
size_type size() const;
stack に格納されている要素の個数を返す。
stack
内部のコンテナの size() メンバ関数を呼ぶ。
size()
return c.size();
stack の内部のコンテナに含まれている要素の個数。
#include <iostream> #include <stack> int main() { std::stack<int> st; // 要素を 1 個追加 st.push(3); // 要素数を表示 std::cout << st.size() << std::endl; // 要素を 5 個追加 st.push(1); st.push(4); st.push(1); st.push(5); st.push(9); // 要素数を表示 std::cout << st.size() << std::endl; }
1 6
size_type size() const { return c.size(); }
empty