This is because cout outputs buffers. You must discard the buffer to actually print it. A.
endl and flush() do this cleanup.
Also note that your program freezes because you have an infinite loop ( while(true); ).
The reason this is done is because if you print a lot of data (for example, 1000 numbers), it can do this much more efficiently. In addition, most of the minor data points end in endl , since you want your output to span multiple lines.
source share