| Types and objects | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Defined in header <stdio.h> | ||
#define stdin /* implementation-defined */ | (1) | |
#define stdout /* implementation-defined */ | (2) | |
#define stderr /* implementation-defined */ | (3) | |
Three text streams are predefined. These streams are implicitly opened and unoriented at program startup.
What constitutes an interactive device is implementation-defined.
These macros are expanded to expressions of typeFILE*.
Contents |
Although not mandated by POSIX, the UNIX convention is thatstdin andstdout are line-buffered if associated with a terminal andstderr is unbuffered.
These macros may be expanded to modifiable lvalues. If any of theseFILE* lvalue is modified, subsequent operations on the corresponding stream result in unspecified or undefined behavior.
This example shows a function equivalent toprintf.
#include <stdarg.h>#include <stdio.h> int my_printf(constchar*restrict fmt, ...){ va_list vl; va_start(vl, fmt);int ret=vfprintf(stdout, fmt, vl); va_end(vl);return ret;} int main(void){ my_printf("Rounding:\t%f %.0f %.32f\n",1.5,1.5,1.3); my_printf("Padding:\t%05.2f %.2f %5.2f\n",1.5,1.5,1.5); my_printf("Scientific:\t%E %e\n",1.5,1.5); my_printf("Hexadecimal:\t%a %A\n",1.5,1.5);}
Possible output:
Rounding: 1.500000 2 1.30000000000000004440892098500626Padding: 01.50 1.50 1.50Scientific: 1.500000E+00 1.500000e+00Hexadecimal: 0x1.8p+0 0X1.8P+0
| object type, capable of holding all information needed to control a C I/O stream (typedef)[edit] | |
C++ documentation forstdin,stdout,stderr | |