Does a program that writes to "stdout" write to a file? the screen? I don't understand what it means to write to stdout.
Stdout, also known as standard output, is the default file descriptor where a process can write output. In Unix-like operating systems, such as Linux, macOS X, and BSD, stdout is defined by the POSIX standard. Its default file descriptor number is 1. In the terminal, standard output defaults to the user's screen.
In computer programming, standard streams are interconnected input and output communication channels between a computer program and its environment when it begins execution. The three input/output (I/O) connections are called standard input (stdin), standard output (stdout) and standard error (stderr).
In C, to print to STDOUT, you may do this: printf("%sn", your_str); For example, $ cat t.c #include <stdio.
That means that you are printing output on the main output device for the session... whatever that may be. The user's console, a tty session, a file or who knows what. What that device may be varies depending on how the program is being run and from where.
The following command will write to the standard output device (stdout)...
printf( "hello world\n" );
Which is just another way, in essence, of doing this...
fprintf( stdout, "hello world\n" );
In which case stdout
is a pointer to a FILE
stream that represents the default output device for the application. You could also use
fprintf( stderr, "that didn't go well\n" );
in which case you would be sending the output to the standard error output device for the application which may, or may not, be the same as stdout
-- as with stdout
, stderr
is a pointer to a FILE
stream representing the default output device for error messages.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With