Nothing did go wrong, but the pop
s get (in your case) evaluated from right to left if you put them all in one std::cout
line. In general. the evaluation order is unspecified. For more detail on this see here.
So you correctly get the elements in reverse order of insertion and then -1
and then print them reversed.