cout question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • coder

    #1

    cout question

    I'm new to C++ and currently I'm trying to make my own stack.

    This is my main() function:

    int main()
    {
    Stack<intiStack ;

    iStack.push(10) ;
    iStack.push(13) ;
    iStack.push(12) ;

    cout << iStack.pop() << endl;
    cout << iStack.pop() << endl;
    cout << iStack.pop() << endl;

    return 0;
    }

    When I run the program, I get the output as:
    12
    13
    10

    which indicates that the program is working OK.


    However, when I change the 3 "popping" lines to the following:

    cout << iStack.pop() << endl << iStack.pop() << endl << iStack.pop()
    << endl;

    the output gets reversed:
    10
    13
    12

    Could anyone explain why is that so?

Working...