Most languages I know of provide one way to directly intreact with the standard output stream, as well as some higher-level formatted output capabilities. C++ has C's file API and stdout
for the lowest level, and printf
and cout
on top of it. Python provides sys.stdout
as a stream object, as well as print
and the logging
module on top. Java has System.out
as a stream object, and some wrappers like java.util.Logger
around it.
Overall, it seems reasonable to provide a single uniform way to interact with the output as a text stream, and then let more specialized API be built on top of it. Some common cases might be implemented in the standard library - like basic formatted printing, for instance. The less common ones could be implemented in community modules - like fmt
for C++ (until it was added to C++20's standard library under std::format
). The benefit to this approach is that the program's output isn't something special, but rather just a specific text stream, and the corresponding API would work just as well with writing to a file, a socket or a buffer.
sys.stdout.write('hello, world\n')
. $\endgroup$cout
is too, but I guess that's arguable. $\endgroup$printf
is mostly just a C holdover. It's not really used in C++ proper and not usually recommended. $\endgroup$