fork download
  1. #include <iostream>
  2. #include <stack>
  3.  
  4. template <typename T>
  5. void print_stack(std::stack<T> st, std::ostream& os = std::cout)
  6. {
  7. while (!st.empty()) {
  8. os << st.top() << " ";
  9. st.pop();
  10. }
  11. os << std::endl;
  12. }
  13.  
  14. int main()
  15. {
  16. std::stack<int> st{{1,2,3,4}};
  17. print_stack(st);
  18. }
Success #stdin #stdout 0s 3276KB
stdin
Standard input is empty
stdout
4 3 2 1