I need help for return second element of stack without pop() ? but I don’t know how can I use.
my code :
stack<int> st;
st.push(10);
st.push(20);
st.top(); // return 20
How do can I make this function is return 10 without pop();
Thanks.
P.S. sorry for my English.
I presume you’re trying to emulate a stack-based machine?
Here’s the only way to do it with std::stack:
If you want other behavior you’ll have to do your own implementation of
stackthat has more capabilities.