📄 stdio.html
字号:
<HTML><HEAD><TITLE><stdio.h></TITLE></HEAD><BODY><H1><A NAME="<stdio.h>"><CODE><stdio.h></CODE></A></H1><HR><P><B><CODE><A HREF="#_IOFBF">_IOFBF</A>· <A HREF="#_IOLBF">_IOLBF</A>· <A HREF="#_IONBF">_IONBF</A>· <A HREF="#BUFSIZ">BUFSIZ</A>· <A HREF="#EOF">EOF</A>· <A HREF="#FILE">FILE</A>· <A HREF="#FILENAME_MAX">FILENAME_MAX</A>· <A HREF="#FOPEN_MAX">FOPEN_MAX</A>· <A HREF="#L_tmpnam">L_tmpnam</A>· <A HREF="#NULL">NULL</A>· <A HREF="#SEEK_CUR">SEEK_CUR</A>· <A HREF="#SEEK_END">SEEK_END</A>· <A HREF="#SEEK_SET">SEEK_SET</A>· <A HREF="#TMP_MAX">TMP_MAX</A></CODE></B></P><P><B><CODE><A HREF="#clearerr">clearerr</A>· <A HREF="#fclose">fclose</A>· <A HREF="#feof">feof</A>· <A HREF="#ferror">ferror</A>· <A HREF="#fflush">fflush</A>· <A HREF="#fgetc">fgetc</A>· <A HREF="#fgetpos">fgetpos</A>· <A HREF="#fgets">fgets</A>· <A HREF="#fopen">fopen</A>· <A HREF="#fpos_t">fpos_t</A>· <A HREF="#fprintf">fprintf</A>· <A HREF="#fputc">fputc</A>· <A HREF="#fputs">fputs</A>· <A HREF="#fread">fread</A>· <A HREF="#freopen">freopen</A>· <A HREF="#fscanf">fscanf</A>· <A HREF="#fseek">fseek</A>· <A HREF="#fsetpos">fsetpos</A>· <A HREF="#ftell">ftell</A>· <A HREF="#fwrite">fwrite</A>· <A HREF="#getc">getc</A>· <A HREF="#getchar">getchar</A>· <A HREF="#gets">gets</A>· <A HREF="#perror">perror</A>· <A HREF="#printf">printf</A>· <A HREF="#putc">putc</A>· <A HREF="#putchar">putchar</A>· <A HREF="#puts">puts</A>· <A HREF="#remove">remove</A>· <A HREF="#rename">rename</A>· <A HREF="#rewind">rewind</A>· <A HREF="#scanf">scanf</A>· <A HREF="#setbuf">setbuf</A>· <A HREF="#setvbuf">setvbuf</A>· <A HREF="#size_t">size_t</A>· <A HREF="#sprintf">sprintf</A>· <A HREF="#sscanf">sscanf</A>· <A HREF="#stderr">stderr</A>· <A HREF="#stdin">stdin</A>· <A HREF="#stdout">stdout</A>· <A HREF="#tmpfile">tmpfile</A>· <A HREF="#tmpnam">tmpnam</A>· <A HREF="#ungetc">ungetc</A>· <A HREF="#vfprintf">vfprintf</A>· <A HREF="#vprintf">vprintf</A>· <A HREF="#vsprintf">vsprintf</A></CODE></B></P><HR><P>Include the standard header <B><CODE><stdio.h></CODE></B>so that you can perform input and output operations on streams and files.</P><PRE> /* MACROS */#define <A HREF="#_IOFBF"><B>_IOFBF</B></A> <I><integer constant expression></I>#define <A HREF="#_IOLBF"><B>_IOLBF</B></A> <I><integer constant expression></I>#define <A HREF="#_IONBF"><B>_IONBF</B></A> <I><integer constant expression></I>#define <A HREF="#BUFSIZ"><B>BUFSIZ</B></A> <I><integer constant expression >= 256></I>#define <A HREF="#EOF"><B>EOF</B></A> <I><integer constant expression < 0></I>#define <A HREF="#FILENAME_MAX"><B>FILENAME_MAX</B></A> <I><integer constant expression > 0></I>#define <A HREF="#FOPEN_MAX"><B>FOPEN_MAX</B></A> <I><integer constant expression >= 8></I>#define <A HREF="#L_tmpnam"><B>L_tmpnam</B></A> <I><integer constant expression > 0></I>#define <A HREF="#NULL"><B>NULL</B></A> <I><either 0, 0L, or (void *)0></I> <B>[0 in C++]</B>#define <A HREF="#SEEK_CUR"><B>SEEK_CUR</B></A> <I><integer constant expression></I>#define <A HREF="#SEEK_END"><B>SEEK_END</B></A> <I><integer constant expression></I>#define <A HREF="#SEEK_SET"><B>SEEK_SET</B></A> <I><integer constant expression></I>#define <A HREF="#TMP_MAX"><B>TMP_MAX</B></A> <I><integer constant expression >= 25></I>#define <A HREF="#stderr"><B>stderr</B></A> <I><pointer to FILE rvalue></I>#define <A HREF="#stdin"><B>stdin</B></A> <I><pointer to FILE rvalue></I>#define <A HREF="#stdout"><B>stdout</B></A> <I><pointer to FILE rvalue></I> /* TYPES */typedef <I>o-type</I> <A HREF="#FILE"><B>FILE</B></A>;typedef <I>o-type</I> <A HREF="#fpos_t"><B>fpos_t</B></A>;typedef <I>ui-type</I> <A HREF="#size_t"><B>size_t</B></A>; /* FUNCTIONS */void <A HREF="#clearerr"><B>clearerr</B></A>(FILE *stream);int <A HREF="#fclose"><B>fclose</B></A>(FILE *stream);int <A HREF="#feof"><B>feof</B></A>(FILE *stream);int <A HREF="#ferror"><B>ferror</B></A>(FILE *stream);int <A HREF="#fflush"><B>fflush</B></A>(FILE *stream);FILE *<A HREF="#fopen"><B>fopen</B></A>(const char *filename, const char *mode);FILE *<A HREF="#freopen"><B>freopen</B></A>(const char *filename, const char *mode, FILE *stream);int <A HREF="#remove"><B>remove</B></A>(const char *filename);int <A HREF="#rename"><B>rename</B></A>(const char *old, const char *new);void <A HREF="#rewind"><B>rewind</B></A>(FILE *stream);void <A HREF="#setbuf"><B>setbuf</B></A>(FILE *stream, char *buf);int <A HREF="#setvbuf"><B>setvbuf</B></A>(FILE *stream, char *buf, int mode, size_t size);FILE *<A HREF="#tmpfile"><B>tmpfile</B></A>(void)char *<A HREF="#tmpnam"><B>tmpnam</B></A>(char *s);int <A HREF="#fseek"><B>fseek</B></A>(FILE *stream, long offset, int mode);int <A HREF="#fsetpos"><B>fsetpos</B></A>(FILE *stream, const fpos_t *pos);int <A HREF="#fgetpos"><B>fgetpos</B></A>(FILE *stream, fpos_t *pos);long <A HREF="#ftell"><B>ftell</B></A>(FILE *stream);int <A HREF="#fgetc"><B>fgetc</B></A>(FILE *stream);char *<A HREF="#fgets"><B>fgets</B></A>(char *s, int n, FILE *stream);size_t <A HREF="#fread"><B>fread</B></A>(void *ptr, size_t size, size_t nelem, FILE *stream);int <A HREF="#getc"><B>getc</B></A>(FILE *stream);int <A HREF="#getchar"><B>getchar</B></A>(void);char *<A HREF="#gets"><B>gets</B></A>(char *s);int <A HREF="#ungetc"><B>ungetc</B></A>(int c, FILE *stream);int <A HREF="#fputc"><B>fputc</B></A>(int c, FILE *stream);int <A HREF="#fputs"><B>fputs</B></A>(const char *s, FILE *stream);size_t <A HREF="#fwrite"><B>fwrite</B></A>(const void *ptr, size_t size, size_t nelem, FILE *stream);void <A HREF="#perror"><B>perror</B></A>(const char *s);int <A HREF="#putc"><B>putc</B></A>(int c, FILE *stream);int <A HREF="#putchar"><B>putchar</B></A>(int c);int <A HREF="#puts"><B>puts</B></A>(const char *s);int <A HREF="#fscanf"><B>fscanf</B></A>(FILE *stream, const char *format, ...);int <A HREF="#scanf"><B>scanf</B></A>(const char *format, ...);int <A HREF="#sscanf"><B>sscanf</B></A>(const char *s, const char *format, ...);int <A HREF="#fprintf"><B>fprintf</B></A>(FILE *stream, const char *format, ...);int <A HREF="#printf"><B>printf</B></A>(const char *format, ...);int <A HREF="#sprintf"><B>sprintf</B></A>(char *s, const char *format, ...);int <A HREF="#vfprintf"><B>vfprintf</B></A>(FILE *stream, const char *format, va_list ap);int <A HREF="#vprintf"><B>vprintf</B></A>(const char *format, va_list ap);int <A HREF="#vsprintf"><B>vsprintf</B></A>(char *s, const char *format, va_list ap);</PRE><H2><A NAME="BUFSIZ"><CODE>BUFSIZ</CODE></A></H2><PRE>#define <B>BUFSIZ</B> <I><integer constant expression >= 256></I></PRE><P>The macro yields the size of the stream buffer used by<A HREF="#setbuf"><CODE>setbuf</CODE></A>.</P><H2><A NAME="clearerr"><CODE>clearerr</CODE></A></H2><PRE>void <B>clearerr</B>(FILE *stream);</PRE><P>The function clears the end-of-file and error indicators forthe stream <CODE>stream</CODE>.</P><H2><A NAME="EOF"><CODE>EOF</CODE></A></H2><PRE>#define <B>EOF</B> <I><integer constant expression < 0></I></PRE><P>The macro yields the return value used to signal the end ofa stream or to report an error condition.</P><H2><A NAME="fclose"><CODE>fclose</CODE></A></H2><PRE>int <B>fclose</B>(FILE *stream);</PRE><P>The function closes the file associated withthe stream <CODE>stream</CODE>.It returns zero if successful; otherwise, it returns<A HREF="#EOF"><CODE>EOF</CODE></A>.<CODE>fclose</CODE> writes any buffered output to the file,deallocates the stream buffer if it was automatically allocated,and removes the association between the stream and the file.Do not use the value of <CODE>stream</CODE> in subsequent expressions.</P><H2><A NAME="feof"><CODE>feof</CODE></A></H2><PRE>int <B>feof</B>(FILE *stream);</PRE><P>The function returns a nonzero value if the end-of-file indicatoris set for the stream <CODE>stream</CODE>.</P><H2><A NAME="ferror"><CODE>ferror</CODE></A></H2><PRE>int <B>ferror</B>(FILE *stream);</PRE><P>The function returns a nonzero value if the error indicatoris set for the stream <CODE>stream</CODE>.</P><H2><A NAME="fflush"><CODE>fflush</CODE></A></H2><PRE>int <B>fflush</B>(FILE *stream);</PRE><P>The function writes any buffered output to the file associatedwith the stream <CODE>stream</CODE> and returns zero if successful;otherwise, it returns<A HREF="#EOF"><CODE>EOF</CODE></A>.If <CODE>stream</CODE> is a null pointer, <CODE>fflush</CODE>writes any buffered output to all files opened for output.</P><H2><A NAME="fgetc"><CODE>fgetc</CODE></A></H2><PRE>int <B>fgetc</B>(FILE *stream);</PRE><P>The function reads the next character <CODE>c</CODE> (if present)from the input stream <CODE>stream</CODE>, advances thefile-position indicator (if defined),and returns <CODE>(int)(unsigned char)c</CODE>. If thefunction sets either the end-of-file indicator or the error indicator,it returns<A HREF="#EOF"><CODE>EOF</CODE></A>.</P><H2><A NAME="fgetpos"><CODE>fgetpos</CODE></A></H2><PRE>int <B>fgetpos</B>(FILE *stream, fpos_t *pos);</PRE><P>The function stores thefile-position indicator for the stream<CODE>stream</CODE> in <CODE>*pos</CODE> and returns zero if successful;otherwise, the function stores a positive value in<A HREF="errno.html#errno"><CODE>errno</CODE></A> and returns anonzero value.</P><H2><A NAME="fgets"><CODE>fgets</CODE></A></H2><PRE>char *<B>fgets</B>(char *s, int n, FILE *stream);</PRE><P>The function reads characters from the input stream <CODE>stream</CODE>and stores them in successive elements of the arraybeginning at <CODE>s</CODE>and continuing until it stores <CODE>n-1</CODE> characters,stores an <CODE><I>NL</I></CODE> character,or sets the end-of-file or error indicators. If <CODE>fgets</CODE>stores any characters, it concludes by storing a null character inthe next element of the array. It returns <CODE>s</CODE> if it stores anycharacters and it has not set the error indicator for the stream;otherwise, it returns a null pointer. If it sets the error indicator,the array contents are indeterminate.</P><H2><A NAME="FILE"><CODE>FILE</CODE></A></H2><PRE>typedef <I>o-type</I> <B>FILE</B>;</PRE><P>The type is an object type <CODE><I>o-type</I></CODE> that stores all<A HREF="lib_file.html#Controlling Streams">control information</A>for a stream. The functions<A HREF="#fopen"><CODE>fopen</CODE></A> and<A HREF="#freopen"><CODE>freopen</CODE></A>allocate all <CODE>FILE</CODE> objects used by the read and write functions.</P><H2><A NAME="FILENAME_MAX"><CODE>FILENAME_MAX</CODE></A></H2><PRE>#define <B>FILENAME_MAX</B> <I><integer constant expression > 0></I></PRE><P>The macro yields the maximum size array of characters that youmust provide to hold a<A HREF="lib_over.html#filename">filename</A>.</P><H2><A NAME="fopen"><CODE>fopen</CODE></A></H2><PRE>FILE *<B>fopen</B>(const char *filename, const char *mode);</PRE><P>The function opens the file with the filename <CODE>filename</CODE>,associates it with a stream, and returns a pointer to the object controllingthe stream. If the open fails, it returns a null pointer. The initialcharacters of <CODE>mode</CODE> determine how the program<A HREF="lib_file.html#Files and Streams">manipulates</A> the streamand whether it interprets the stream as<A HREF="lib_file.html#Text and Binary Streams">text or binary</A>.The initial characters must be one of the following sequences:</P><UL><LI><B><CODE>"r"</CODE></B> -- to open an existing text file for reading<LI><B><CODE>"w"</CODE></B> -- to create a text file or to open and truncatean existing text file, for writing<LI><B><CODE>"a"</CODE></B> -- to create a text file or to openan existing text file, for writing. Thefile-position indicator is positionedat the end of the file before each write<LI><B><CODE>"rb"</CODE></B> -- to open an existing binary file for reading<LI><B><CODE>"wb"</CODE></B> -- to create a binary file or to open and truncatean existing binary file, for writing<LI><B><CODE>"ab"</CODE></B> -- to create a binary file or to open an existingbinary file, for writing. Thefile-position indicator is positionedat the end of the file (possibly after arbitrary null byte padding)before each write<LI><B><CODE>"r+"</CODE></B> -- to open an existing text file for readingand writing<LI><B><CODE>"w+"</CODE></B> -- to create a text file or to open and truncatean existing text file, for reading and writing<LI><B><CODE>"a+"</CODE></B> -- to create a text file or to open an existingtext file, for reading and writing. Thefile-position indicator is positionedat the end of the file before each write<LI><B><CODE>"r+b"</CODE></B> or <B><CODE>"rb+"</CODE></B> -- to open an existing binaryfile for reading and writing<LI><B><CODE>"w+b"</CODE></B> or <B><CODE>"wb+"</CODE></B> -- to create a binary file orto open and truncate an existing binary file, for reading and writing<LI><B><CODE>"a+b"</CODE></B> or <B><CODE>"ab+"</CODE></B> -- to create a binary file orto open an existing binary file, for reading and writing. Thefile-position indicator is positionedat the end of the file (possibly after arbitrarynull byte padding) before each write</UL><P>If you open a file for both reading and writing, the targetenvironment can open a binary file instead of a text file. If thefile is not interactive, the stream is fully buffered.</P><H2><A NAME="FOPEN_MAX"><CODE>FOPEN_MAX</CODE></A></H2><PRE>#define <B>FOPEN_MAX</B> <I><integer constant expression >= 8></I></PRE><P>The macro yields the maximum number of files that the targetenvironment permits to be simultaneously open (including<A HREF="#stderr"><CODE>stderr</CODE></A>,<A HREF="#stdin"><CODE>stdin</CODE></A>, and<A HREF="#stdout"><CODE>stdout</CODE></A>).</P>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -