how to access and individual item from a stack?

i want to get the item just before the last item in a stack. is it possible, and if so how?

i've tried it myself by doing:

stack <int> S;
///push stuff
cout << S.top()-1;

it didn't work
The point of a stack is that you can only access the top.
You can pop until the position you want to check and then push everything back in the stack
Topic archived. No new replies allowed.