The code works OK except when I want to test the extra pop that leads to the Error message(Line 42), it gives me an additional,unintended line of output of "16384". What is wrong with my program and how to fix it? Thanks.
as an operator that returns an int, >> must return and int. You could use try catch blocks, or make another function to check if the stack is empty. Then you can just simply make a loop that outputs until it is empty.