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::push - cpprefjp C++日本語リファレンス

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

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

履歴 編集

function
<stack>

std::stack::push

void push(const value_type& x);           // (1) C++98
constexpr void push(const value_type& x); // (1) C++26

void push(value_type&& x);           // (2) C++11
constexpr void push(value_type&& x); // (2) C++26

概要

新しい要素を stack の末尾に追加し、そのインスタンスをxのコピー、もしくはムーブして初期化する。

効果

  • (1) :

    c.push_back(x);
    

  • (2) :

    c.push_back(std::move(x));
    

戻り値

なし

計算量

Container::push_back()と同じ。

例

#include <iostream>
#include <stack>

int main()
{
  std::stack<int> st;

  // 要素を追加
  st.push(1);
  st.push(2);
  st.push(3);

  while (!st.empty()) {
    std::cout << st.top() << " "; // 末尾要素を参照する
    st.pop(); // 末尾要素を削除
  }
}

出力

3 2 1 

実装例

void push(const value_type& x) { c.push_back(x); }
void push(value_type&& x) { c.push_back(std::move(x)); }

参照

  • 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.