std::stack

cppreference.com

Example

reportStackSize: (s: std::stack<int>) = {
    std::cout << "(s.size())$ elements on stack\n";
}
 
reportStackTop: (s: std::stack<int>) = {
    // Leaves element on stack
    std::cout << "Top element: (s.top())$\n";
}
 
main: () = {
    s: std::stack<int> = ();
    s.push(2);
    s.push(6);
    s.push(51);
 
    reportStackSize(s);
    reportStackTop(s);
 
    reportStackSize(s);
    s.pop();
 
    reportStackSize(s);
    reportStackTop(s);
}

Output

3 elements on stack
Top element: 51
3 elements on stack
2 elements on stack
Top element: 6

Back to top

cpp2reference.com licensed under CC-BY-SA and GFDL.