⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 iostream.html

📁 vxworks相关论文
💻 HTML
📖 第 1 页 / 共 5 页
字号:
<P><DL><DT><U>Method:</U> istream&#38; <B>istream::read</B> <I>(<VAR>pointer</VAR>, int <VAR>len</VAR>)</I><DD><A NAME="IDX97"></A>Read <VAR>len</VAR> bytes into the location at <VAR>pointer</VAR>, unless theinput ends first.</P><P><VAR>pointer</VAR> may be of type <CODE>char*</CODE>, <CODE>void*</CODE>, <CODE>unsignedchar*</CODE>, or <CODE>signed char*</CODE>.</P><P>If the <CODE>istream</CODE> ends before reading <VAR>len</VAR> bytes, <CODE>read</CODE>sets the <CODE>ios::fail</CODE> flag.</DL></P><P><DL><DT><U>Method:</U> istream&#38; <B>istream::gets</B> <I>(char **<VAR>s</VAR> [, char <VAR>delim</VAR>])</I><DD><A NAME="IDX98"></A>A GNU extension, to read an arbitrarily long stringfrom the current input position to the next instance of the <VAR>delim</VAR>character (newline <CODE>\n</CODE> by default).</P><P>To permit reading a string of arbitrary length, <CODE>gets</CODE> allocateswhatever memory is required.  Notice that the first argument <VAR>s</VAR> isan address to record a character pointer, rather than the pointeritself.</DL></P><P><DL><DT><U>Method:</U> istream&#38; <B>istream::scan</B> <I>(const char *format ...)</I><DD><A NAME="IDX99"></A>A GNU extension, similar to <CODE>fscanf(<VAR>file</VAR>,<VAR>format</VAR>, ...)</CODE>.  The <VAR>format</VAR> is a <CODE>scanf</CODE>-style formatcontrol string, which is used to read the variables in the remainder ofthe argument list from the <CODE>istream</CODE>.</DL></P><P><DL><DT><U>Method:</U> istream&#38; <B>istream::vscan</B> <I>(const char *format, va_list args)</I><DD><A NAME="IDX100"></A>Like <CODE>istream::scan</CODE>, but takes a single <CODE>va_list</CODE> argument.</DL></P><H3><A NAME="SEC20" HREF="iostream_toc.html#TOC20">Repositioning an <CODE>istream</CODE></A></H3><P>Use these methods to control the current input position:</P><P><DL><DT><U>Method:</U> streampos <B>istream::tellg</B> <I>()</I><DD><A NAME="IDX101"></A>Return the current read position, so that you can save it and return toit later with <CODE>istream::seekg</CODE>.</DL></P><P><DL><DT><U>Method:</U> istream&#38; <B>istream::seekg</B> <I>(streampos <VAR>p</VAR>)</I><DD><A NAME="IDX102"></A>Reset the input pointer (if the input device permits it) to <VAR>p</VAR>,usually the result of an earlier call to <CODE>istream::tellg</CODE>.</DL></P><P><DL><DT><U>Method:</U> istream&#38; <B>istream::seekg</B> <I>(streamoff <VAR>offset</VAR>, ios::seek_dir <VAR>ref</VAR>)</I><DD><A NAME="IDX103"></A>Reset the input pointer (if the input device permits it) to <VAR>offset</VAR>characters from the beginning of the input, the current position, or theend of input.  Specify how to interpret <VAR>offset</VAR> with one of thesevalues for the second argument:</P><DL COMPACT><DT><CODE>ios::beg</CODE><DD><A NAME="IDX104"></A>Interpret <VAR>loc</VAR> as an absolute offset from the beginning of thefile.<DT><CODE>ios::cur</CODE><DD><A NAME="IDX105"></A>Interpret <VAR>loc</VAR> as an offset relative to the current outputposition.<DT><CODE>ios::end</CODE><DD><A NAME="IDX106"></A>Interpret <VAR>loc</VAR> as an offset from the current end of the outputstream.</DL></DL><H3><A NAME="SEC21" HREF="iostream_toc.html#TOC21">Miscellaneous <CODE>istream</CODE> utilities</A></H3><P>Use these methods for housekeeping on <CODE>istream</CODE> objects:</P><P><DL><DT><U>Method:</U> int <B>istream::gcount</B> <I>()</I><DD><A NAME="IDX107"></A>Report how many characters were read from this <CODE>istream</CODE> in thelast unformatted input operation.</DL></P><P><DL><DT><U>Method:</U> int <B>istream::ipfx</B> <I>(int <VAR>keepwhite</VAR>)</I><DD><A NAME="IDX108"></A>Ensure that the <CODE>istream</CODE> object is ready for reading; check forerrors and end of file and flush any tied stream.  <CODE>ipfx</CODE> skipswhitespace if you specify <CODE>0</CODE> as the <VAR>keepwhite</VAR>argument, <EM>and</EM> <CODE>ios::skipws</CODE> is set for this stream.</P><P>To avoid skipping whitespace (regardless of the <CODE>skipws</CODE> setting onthe stream), use <CODE>1</CODE> as the argument.</P><P>Call <CODE>istream::ipfx</CODE> to simplify writing your own methods for reading<CODE>istream</CODE> objects.</DL></P><P><DL><DT><U>Method:</U> void <B>istream::isfx</B> <I>()</I><DD><A NAME="IDX109"></A>A placeholder for compliance with the draft ANSI standard; thismethod does nothing whatever.</P><P>If you wish to write portable standard-conforming code on <CODE>istream</CODE>objects, call <CODE>isfx</CODE> after any operation that reads from an<CODE>istream</CODE>; if <CODE>istream::ipfx</CODE> has any special effects thatmust be cancelled when done, <CODE>istream::isfx</CODE> will cancel them.</DL></P><P><DL><DT><U>Method:</U> istream&#38; <B>istream::ignore</B> <I>([int <VAR>n</VAR>] [, int <VAR>delim</VAR>])</I><DD><A NAME="IDX110"></A>Discard some number of characters pending input.  The first optionalargument <VAR>n</VAR> specifies how many characters to skip.  The secondoptional argument <VAR>delim</VAR> specifies a "boundary" character:<CODE>ignore</CODE> returns immediately if this character appears in theinput.</P><P>By default, <VAR>delim</VAR> is <CODE>EOF</CODE>; that is, if you do not specify asecond argument, only the count <VAR>n</VAR> restricts how much to ignore(while input is still available).</P><P>If you do not specify how many characters to ignore, <CODE>ignore</CODE>returns after discarding only one character.</DL></P><P><DL><DT><U>Method:</U> istream&#38; <B>istream::putback</B> <I>(char <VAR>ch</VAR>)</I><DD><A NAME="IDX111"></A>Attempts to back up one character, replacing the character backed-upover by <VAR>ch</VAR>.  Returns <CODE>EOF</CODE> if this is not allowed.  Puttingback the most recently read character is always allowed.  (This methodcorresponds to the C function <CODE>ungetc</CODE>.)</DL></P><P><DL><DT><U>Method:</U> istream&#38; <B>istream::unget</B> <I>()</I><DD><A NAME="IDX112"></A>Attempt to back up one character.</DL></P><H2><A NAME="SEC22" HREF="iostream_toc.html#TOC22">Input and output together: class <CODE>iostream</CODE></A></H2><P>If you need to use the same stream for input and output, you can use anobject of the class <CODE>iostream</CODE>, which is derived from <EM>both</EM><CODE>istream</CODE> and <CODE>ostream</CODE>.</P><P>The constructors for <CODE>iostream</CODE> behave just like the constructorsfor <CODE>istream</CODE>.</P><P><DL><DT><U>Constructor:</U>  <B>iostream::iostream</B> <I>()</I><DD><A NAME="IDX113"></A>When used without arguments, the <CODE>iostream</CODE> constructor simplyallocates a new <CODE>ios</CODE> object, and initializes the input counter(the value reported by <CODE>istream::gcount</CODE>) to <CODE>0</CODE>.</DL></P><P><DL><DT><U>Constructor:</U>  <B>iostream::iostream</B> <I>(streambuf* <VAR>sb</VAR> [, ostream* <VAR>tie</VAR>])</I><DD><A NAME="IDX114"></A>You can also call a constructor with one or two arguments.  The firstargument <VAR>sb</VAR> is a <CODE>streambuf*</CODE>; if you supply this pointer,the constructor uses that <CODE>streambuf</CODE> for input and output.</P><P>You can use the optional second argument <VAR>tie</VAR> (an <CODE>ostream*</CODE>)to specify a related output stream as the initial value for<CODE>ios::tie</CODE>.</DL></P><P><A NAME="IDX115"></A><A NAME="IDX116"></A>As for <CODE>ostream</CODE> and <CODE>istream</CODE>, <CODE>iostream</CODE> simply usesthe <CODE>ios</CODE> destructor.  However, an <CODE>iostream</CODE> is not deleted byits destructor.</P><P>You can use all the <CODE>istream</CODE>, <CODE>ostream</CODE>, and <CODE>ios</CODE>methods with an <CODE>iostream</CODE> object.</P><H1><A NAME="SEC23" HREF="iostream_toc.html#TOC23">Classes for Files and Strings</A></H1><P>There are two very common special cases of input and output: using files,and using strings in memory.</P><P><CODE>libio</CODE> defines four specialized classes for these cases:</P><DL COMPACT><DT><CODE>ifstream</CODE><DD><A NAME="IDX117"></A>Methods for reading files.<DT><CODE>ofstream</CODE><DD><A NAME="IDX118"></A>Methods for writing files.<DT><CODE>istrstream</CODE><DD><A NAME="IDX119"></A>Methods for reading strings from memory.<DT><CODE>ostrstream</CODE><DD><A NAME="IDX120"></A>Methods for writing strings in memory.</DL><H2><A NAME="SEC24" HREF="iostream_toc.html#TOC24">Reading and writing files</A></H2><P>These methods are declared in <TT>`fstream.h'</TT>.</P><P><A NAME="IDX121"></A><A NAME="IDX122"></A>You can read data from class <CODE>ifstream</CODE> with any operation from class<CODE>istream</CODE>.  There are also a few specialized facilities:</P><P><DL><DT><U>Constructor:</U>  <B>ifstream::ifstream</B> <I>()</I><DD><A NAME="IDX123"></A>Make an <CODE>ifstream</CODE> associated with a new file for input.  (If youuse this version of the constructor, you need to call<CODE>ifstream::open</CODE> before actually reading anything)</DL></P><P><DL><DT><U>Constructor:</U>  <B>ifstream::ifstream</B> <I>(int <VAR>fd</VAR>)</I><DD><A NAME="IDX124"></A>Make an <CODE>ifstream</CODE> for reading from a file that was already open,using file descriptor <VAR>fd</VAR>.  (This constructor is compatible withother versions of iostreams for POSIX systems, but is not part ofthe ANSI working paper.)</DL></P><P><DL><DT><U>Constructor:</U>  <B>ifstream::ifstream</B> <I>(const char* <VAR>fname</VAR> [, int <VAR>mode</VAR> [, int <VAR>prot</VAR>]])</I><DD><A NAME="IDX125"></A>Open a file <CODE>*<VAR>fname</VAR></CODE> for this <CODE>ifstream</CODE> object.</P><P>By default, the file is opened for input (with <CODE>ios::in</CODE> as<VAR>mode</VAR>).  If you use this constructor, the file will be closed whenthe <CODE>ifstream</CODE> is destroyed.</P><P>You can use the optional argument <VAR>mode</VAR> to specify how to open thefile, by combining these enumerated values (with <SAMP>`|'</SAMP> bitwise or).(These values are actually defined in class <CODE>ios</CODE>, so that allfile-related streams may inherit them.)  Only some of these modes aredefined in the latest draft ANSI specification; if portability isimportant, you may wish to avoid the others.</P><DL COMPACT><DT><CODE>ios::in</CODE><DD><A NAME="IDX126"></A>Open for input.  (Included in ANSI draft.)<DT><CODE>ios::out</CODE><DD><A NAME="IDX127"></A>Open for output.  (Included in ANSI draft.)<DT><CODE>ios::ate</CODE><DD><A NAME="IDX128"></A>Set the initial input (or output) position to the end of the file.<DT><CODE>ios::app</CODE><DD><A NAME="IDX129"></A>Seek to end of file before each write.  (Included in ANSI draft.)<DT><CODE>ios::trunc</CODE><DD><A NAME="IDX130"></A>Guarantee a fresh file; discard any contents that were previouslyassociated with it.<DT><CODE>ios::nocreate</CODE><DD><A NAME="IDX131"></A>Guarantee an existing file; fail if the specified file did not alreadyexist.<DT><CODE>ios::noreplace</CODE><DD><A NAME="IDX132"></A>Guarantee a new file; fail if the specified file already existed.<DT><CODE>ios::bin</CODE><DD><A NAME="IDX133"></A>Open as a binary file (on systems where binary and text files have differentproperties, typically how <SAMP>`\n'</SAMP> is mapped; included in ANSI draft).</DL><P>The last optional argument <VAR>prot</VAR> is specific to Unix-like systems;it specifies the file protection (by default <SAMP>`644'</SAMP>).</DL></P><P><DL><DT><U>Method:</U> void <B>ifstream::open</B> <I>(const char* <VAR>fname</VAR> [, int <VAR>mode</VAR> [, int <VAR>prot</VAR>]])</I><DD><A NAME="IDX134"></A>Open a file explicitly after the associated <CODE>ifstream</CODE> objectalready exists (for instance, after using the default constructor).  Thearguments, options and defaults all have the same meanings as in thefully specified <CODE>ifstream</CODE> constructor.</DL></P><P><A NAME="IDX135"></A><A NAME="IDX136"></A>You can write data to class <CODE>ofstream</CODE> with any operation from class<CODE>ostream</CODE>.  There are also a few specialized facilities:</P><P><DL><DT><U>Constructor:</U>  <B>ofstream::ofstream</B> <I>()</I><DD><A NAME="IDX137"></A>Make an <CODE>ofstream</CODE> associated with a new file for output.</DL></P><P><DL><DT><U>Constructor:</U>  <B>ofstream::ofstream</B> <I>(int <VAR>fd</VAR>)</I><DD><A NAME="IDX138"></A>Make an <CODE>ofstream</CODE> for writing to a file that was already open,using file descriptor <VAR>fd</VAR>.</DL></P><P><DL><DT><U>Constructor:</U>  <B>ofstream::ofstream</B> <I>(const char* <VAR>fname</VAR> [, int <VAR>mode</VAR> [, int <VAR>prot</VAR>]])</I><DD><A NAME="IDX139"></A>Open a file <CODE>*<VAR>fname</VAR></CODE> for this <CODE>ofstream</CODE> object.</P><P>By default, the file is opened for output (with <CODE>ios::out</CODE> as <VAR>mode</VAR>).You can use the optional argument <VAR>mode</VAR> to specify how to open the

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -