fork download
  1. #include <iostream>
  2. #include <stack>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. stack<int> s;
  8.  
  9. s.push(10);
  10. s.push(20);
  11. s.push(30);
  12. s.push(40);
  13.  
  14. cout << "Stack elements (Top to Bottom):" << endl;
  15. while (!s.empty())
  16. {
  17. cout << s.top() << " ";
  18. s.pop();
  19. }
  20.  
  21. return 0;
  22. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Stack elements (Top to Bottom):
40 30 20 10