diff options
Diffstat (limited to 'devdocs/c/io%2Fstd_streams.html')
| -rw-r--r-- | devdocs/c/io%2Fstd_streams.html | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/devdocs/c/io%2Fstd_streams.html b/devdocs/c/io%2Fstd_streams.html new file mode 100644 index 00000000..be45707e --- /dev/null +++ b/devdocs/c/io%2Fstd_streams.html @@ -0,0 +1,68 @@ + <h1 id="firstHeading" class="firstHeading">stdin, stdout, stderr</h1> <table class="t-dcl-begin"> <tr class="t-dsc-header"> <th> Defined in header <code><stdio.h></code> </th> <th> </th> <th> </th> </tr> <tr class="t-dcl"> <td> <pre data-language="c">#define stdin /* implementation-defined */</pre> +</td> <td> (1) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl"> <td> <pre data-language="c">#define stdout /* implementation-defined */</pre> +</td> <td> (2) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl"> <td> <pre data-language="c">#define stderr /* implementation-defined */</pre> +</td> <td> (3) </td> <td class="t-dcl-nopad"> </td> </tr> </table> <p>Three text streams are predefined. These streams are implicitly opened and unoriented at program startup.</p> +<div class="t-li1"> +<span class="t-li">1)</span> Associated with the <i>standard input</i> stream, used for reading conventional input. At program startup, the stream is fully buffered if and only if the stream can be determined to not refer to an interactive device.</div> <div class="t-li1"> +<span class="t-li">2)</span> Associated with the <i>standard output</i> stream, used for writing conventional output. At program startup, the stream is fully buffered if and only if the stream can be determined to not refer to an interactive device.</div> <div class="t-li1"> +<span class="t-li">3)</span> Associated with the <i>standard error</i> stream, used for writing diagnostic output. At program startup, the stream is not fully buffered.</div> <p>What constitutes an interactive device is implementation-defined.</p> +<p>These macros are expanded to expressions of type <code><a href="http://en.cppreference.com/w/c/io/FILE"><span class="kw884">FILE</span></a><span class="sy2">*</span></code>.</p> +<h3 id="Notes"> Notes</h3> <p>Although not mandated by POSIX, the UNIX convention is that <code>stdin</code> and <code>stdout</code> are line-buffered if associated with a terminal and <code>stderr</code> is unbuffered.</p> +<p>These macros may be expanded to modifiable lvalues. If any of these <code><a href="http://en.cppreference.com/w/c/io/FILE"><span class="kw884">FILE</span></a><span class="sy2">*</span></code> lvalue is modified, subsequent operations on the corresponding stream result in unspecified or undefined behavior.</p> +<h3 id="Example"> Example</h3> <div class="t-example"> +<p>This example shows a function equivalent to <code><a href="fprintf" title="c/io/fprintf">printf</a></code>.</p> +<div class="c source-c"><pre data-language="c">#include <stdarg.h> +#include <stdio.h> + +int my_printf(const char * 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); +}</pre></div> <p>Possible output:</p> +<div class="text source-text"><pre data-language="c">Rounding: 1.500000 2 1.30000000000000004440892098500626 +Padding: 01.50 1.50 1.50 +Scientific: 1.500000E+00 1.500000e+00 +Hexadecimal: 0x1.8p+0 0X1.8P+0</pre></div> </div> <h3 id="References"> References</h3> <ul> +<li> C17 standard (ISO/IEC 9899:2018): </li> +<ul> +<li> 7.21.1 Introduction (p: 217-218) </li> +<li> 7.21.2 Streams (p: 217-219) </li> +<li> 7.21.2 Files (p: 219-221) </li> +</ul> +<li> C11 standard (ISO/IEC 9899:2011): </li> +<ul> +<li> 7.21.1 Introduction (p: 296-298) </li> +<li> 7.21.2 Streams (p: 298-299) </li> +<li> 7.21.2 Files (p: 300-302) </li> +</ul> +<li> C99 standard (ISO/IEC 9899:1999): </li> +<ul> +<li> 7.19.1 Introduction (p: 262-264) </li> +<li> 7.19.2 Streams (p: 264-265) </li> +<li> 7.19.2 Files (p: 266-268) </li> +</ul> +<li> C89/C90 standard (ISO/IEC 9899:1990): </li> +<ul> +<li> 7.9.1 Introduction </li> +<li> 7.9.2 Streams </li> +<li> 7.9.3 Files </li> +</ul> +</ul> <h3 id="See_also"> See also</h3> <table class="t-dsc-begin"> <tr class="t-dsc"> <td> <div><a href="file" title="c/io/FILE"> <span class="t-lines"><span>FILE</span></span></a></div> </td> <td> object type, capable of holding all information needed to control a C I/O stream <br> <span class="t-mark">(typedef)</span> </td> +</tr> <tr class="t-dsc"> <td colspan="2"> <span><a href="https://en.cppreference.com/w/cpp/io/c/std_streams" title="cpp/io/c/std streams">C++ documentation</a></span> for <code>stdin, stdout, stderr</code> </td> +</tr> </table> <div class="_attribution"> + <p class="_attribution-p"> + © cppreference.com<br>Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.<br> + <a href="https://en.cppreference.com/w/c/io/std_streams" class="_attribution-link">https://en.cppreference.com/w/c/io/std_streams</a> + </p> +</div> |
