In the following code:
#include <iostream> using namespace std; int f() { throw 1; } int main() { try { cout << "Output: " << f() << endl; } catch (int x) { cout << x; } }
Why is it not printed "Output: "? Shouldn't you call operator<<(cout, "Output: ")up to operator<<(cout, f())? If the string is atomic, then how is the postback printed?
"Output: "
operator<<(cout, "Output: ")
operator<<(cout, f())
The order in which the argument is evaluated for <operator is not defined in the C ++ standard. It looks like your compiler first evaluates all the arguments before printing.
, operator<<(operator<<(operator<<(cout, "Output:"), f()), endl): , operator<<(cout, "Output:") f() operator<<: .
operator<<(operator<<(operator<<(cout, "Output:"), f()), endl)
operator<<(cout, "Output:")
f()
operator<<