Freigeben über


stack::push

Fügt ein Element am oberen Ende des Stapels hinzu.

void push(
   const Type& _Val
);

Parameter

  • _Val
    Das Element hinzugefügt zum Anfang des Stapels.

Hinweise

Die Rand des Stapels ist die Position, die zuletzt vom hinzugefügte Element eingenommen wurde und das letzte Element am Ende des Containers.

Beispiel

// stack_push.cpp
// compile with: /EHsc
#include <stack>
#include <iostream>

int main( )
{
   using namespace std;
   stack <int> s1;

   s1.push( 10 );
   s1.push( 20 );
   s1.push( 30 );

   stack <int>::size_type i;
   i = s1.size( );
   cout << "The stack length is " << i << "." << endl;

   i = s1.top( );
   cout << "The element at the top of the stack is "
        << i << "." << endl;
}
  
  

Anforderungen

Header: <stack>

Namespace: std

Siehe auch

Referenz

stack Class

Standardvorlagenbibliothek