This is amazing. printf() takes priority in this simple program:
Am Fri, 29 Nov 2024 05:35:54 +0000
schrieb Student Project <student@invalid.invalid>:
This is amazing. printf() takes priority in this simple program:
This is simply due to the fact that cout has not yet been flushed. Use
Am 29.11.2024 um 11:13 schrieb Muttley@DastardlyHQ.org:
It works as expected on MacOS. The newline should automatically flush cout >> stdout just as it does in printf regardless of whether the C and C++ streams >> are linked.
std::endl guarantees a flush, but not \n.
I use that often to have buffering of multiple lines.
Am 29.11.2024 um 11:29 schrieb Muttley@DastardlyHQ.org:
On Fri, 29 Nov 2024 11:25:41 +0100
Bonita Montero <Bonita.Montero@gmail.com> wibbled:
Am 29.11.2024 um 11:13 schrieb Muttley@DastardlyHQ.org:
It works as expected on MacOS. The newline should automatically flush cout >>>> stdout just as it does in printf regardless of whether the C and C++ >streams
are linked.
std::endl guarantees a flush, but not \n.
I use that often to have buffering of multiple lines.
I've never seen \n NOT flush stdout. ..
I'm talking about cout, not stdout.
Am 29.11.2024 um 13:04 schrieb Muttley@DastardlyHQ.org:
On Fri, 29 Nov 2024 13:03:01 +0100
Bonita Montero <Bonita.Montero@gmail.com> wibbled:
Am 29.11.2024 um 11:29 schrieb Muttley@DastardlyHQ.org:
On Fri, 29 Nov 2024 11:25:41 +0100streams
Bonita Montero <Bonita.Montero@gmail.com> wibbled:
Am 29.11.2024 um 11:13 schrieb Muttley@DastardlyHQ.org:
It works as expected on MacOS. The newline should automatically flush >cout
stdout just as it does in printf regardless of whether the C and C++
are linked.
std::endl guarantees a flush, but not \n.
I use that often to have buffering of multiple lines.
I've never seen \n NOT flush stdout. ..
I'm talking about cout, not stdout.
Where do you think cout writes to?
The buffering between stdout and cout is not forcfully joined.
On Fri, 29 Nov 2024 11:25:41 +0100
Bonita Montero <Bonita.Montero@gmail.com> wibbled:
Am 29.11.2024 um 11:13 schrieb Muttley@DastardlyHQ.org:
It works as expected on MacOS. The newline should automatically flush cout >>> stdout just as it does in printf regardless of whether the C and C++ streams
are linked.
std::endl guarantees a flush, but not \n.
I use that often to have buffering of multiple lines.
I've never seen \n NOT flush stdout. Perhaps things are different in a Windows
console. Possibly there's some glibc option that may change it on linux and similar on Mac but by default it flushes.
On 11/29/24 05:29, Muttley@DastardlyHQ.org wrote:
On Fri, 29 Nov 2024 11:25:41 +0100
Bonita Montero <Bonita.Montero@gmail.com> wibbled:
Am 29.11.2024 um 11:13 schrieb Muttley@DastardlyHQ.org:
It works as expected on MacOS. The newline should automatically flush cout >>>> stdout just as it does in printf regardless of whether the C and C++ >streams
are linked.
std::endl guarantees a flush, but not \n.
I use that often to have buffering of multiple lines.
I've never seen \n NOT flush stdout. Perhaps things are different in a >Windows
console. Possibly there's some glibc option that may change it on linux and >> similar on Mac but by default it flushes.
The C++ standard defines cout as managing the stdout stream. All other >statements in the C++ standard about stdout merely cross-reference the >definition in the C standard, without saying anything C++ specific about
it. The C standard associates it with the standard output stream, about
which it says:
"As initially opened, ... the standard input and standard output streams
are fully buffered if and only if the stream can be determined not to
refer to an interactive device."
So stdout should be fully buffered, not line buffered, if it can be >determined to refer to an interactive device (such as a computer
terminal). In that case, '\n" should not, in itself, trigger a flush.
James Kuyper <jameskuyper@alumni.caltech.edu> writes:...
"As initially opened, ... the standard input and standard output streams
are fully buffered if and only if the stream can be determined not to
refer to an interactive device."
So stdout should be fully buffered, not line buffered, if it can be
determined to refer to an interactive device (such as a computer
terminal). In that case, '\n" should not, in itself, trigger a flush.
I think you missed a "not" (unless I missed something myself).
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 495 |
Nodes: | 16 (2 / 14) |
Uptime: | 51:32:59 |
Calls: | 9,749 |
Calls today: | 9 |
Files: | 13,742 |
Messages: | 6,184,788 |