Is std::cout buffered?

后端 未结 5 2030
生来不讨喜
生来不讨喜 2020-12-03 13:41

Just reading an old but interesting article by \"Scott Meyers\"

http://aristeia.com/Papers/C++ReportColumns/novdec95.pdf

Basically it is about preferring to

5条回答
  •  旧巷少年郎
    2020-12-03 14:12

    The C++ standard defines all input and output as being "as if" all reading and writing ultimately happened via reads and writes of C streams ([iostream.objects.overview]):

    The header declares objects that associate objects with the standard C streams provided for by the functions declared in (27.9.2), and includes all the headers necessary to use these objects.

    For the behavior of the standard C streams attached to those objects, we have to refer to the C standard (§7.19.3):

    At program startup, three text streams are predefined and need not be opened explicitly — standard input (for reading conventional input), standard output (for writing conventional output), and standard error (for writing diagnostic output). As initially opened, the standard error stream is not fully buffered; 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.

    Here I'm quoting from the C99 standard, but I'm reasonably certain that (modulo changes in section numbering) the same is in all versions of the C standard.

提交回复
热议问题