It is an error to call the member function pop() on an empty stack. If you are not sure whether a stack contains any elements, you can use the member function empty() to check it first:
stack stk;//_many lines of codeif (!stk.empty() ) //test stack before popping it{ stk.pop(); }