您在这里依赖未定义的行为 - 如果您不使用 std::endl,没有任何保证它不会刷新。不要依赖未定义或假定的行为——只依赖明确指定的行为。
详细说明:
1.3.24 [defns.undefined]
undefined behavior
behavior for which this International Standard imposes no requirements
[ Note: Undefined behavior may be expected when this International Standard omits any explicit definition of
behavior or when a program uses an erroneous construct or erroneous data. Permissible undefined behavior
ranges from ignoring the situation completely with unpredictable results, to behaving during translation or
program execution in a documented manner characteristic of the environment (with or without the issuance of
a diagnostic message), to terminating a translation or execution (with the issuance of a diagnostic message).
Many erroneous program constructs do not engender undefined behavior; they are required to be diagnosed.
— end note ]
c++11 或 c++03 对 user2585330 所依赖的行为没有任何要求。