on cout,

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

    #1

    on cout,

    Why cout << "Test: " << foobar() << endl;

    calls foobar first? It seems:

    cout.operator<< ("Test: ").operator<<(f oobar()).operat or(endl);

    would mean "Test: " is output first.

  • benben

    #2
    Re: on cout,

    vsgdp wrote:
    Why cout << "Test: " << foobar() << endl;
    >
    calls foobar first? It seems:
    >
    cout.operator<< ("Test: ").operator<<(f oobar()).operat or(endl);
    >
    would mean "Test: " is output first.
    >
    If you want order then put them in separate statements:

    cout << "Test: ";
    cout << foobar();
    cout << endl;

    A chained operation like the one you posted only guarantees that the
    outputs are in order. The order of evaluation of subexpressions is up to
    the compiler.

    Ben

    Comment

    Working...