GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • cpprefjp - C++日本語リファレンス
  • GitHub Project

This view

  • Original page
  • New address

GeezerVison is showing cpprefjp.github.io — std::stack::size - cpprefjp C++日本語リファレンス

  1. リファレンス
  2. stack
  3. stack
  4. size

最終更新日時: 2026年08月25日 12時11分17秒 (JST)
Akira Takahashi が更新

履歴 編集

function
<stack>

std::stack::size

size_type size() const;           // (1) C++98
constexpr size_type size() const; // (1) C++26

概要

stack に格納されている要素の個数を返す。

内部のコンテナの 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 コンテナが空であるかを確認する

参照

  • P3372R3 constexpr containers and adaptors
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.