📄 istream.html
字号:
<CODE><A HREF="#basic_istream::gcount">gcount</A>()</CODE>.</P><H3><A NAME="basic_istream::seekg"><CODE>basic_istream::seekg</CODE></A></H3><PRE>basic_istream& <B>seekg</B>(pos_type pos);basic_istream& <B>seekg</B>(off_type off, ios_base::seek_dir way);</PRE><P>If <CODE><A HREF="ios.html#basic_ios::fail">fail</A>()</CODE> is false,the first member function calls<CODE>newpos = <A HREF="ios.html#basic_ios::rdbuf">rdbuf</A>()-><A HREF="streambu.html#basic_streambuf::pubseekpos">pubseekpos</A>(pos,<A HREF="ios.html#ios_base::in">in</A>)</CODE>,for some <CODE>pos_type</CODE> temporary object <CODE>newpos</CODE>.If <CODE>fail()</CODE> is false, the second function calls<CODE>newpos = rdbuf()-><A HREF="streambu.html#basic_streambuf::pubseekoff">pubseekoff</A>(off, way,<A HREF="ios.html#ios_base::in">in</A>)</CODE>.In either case, if <CODE>(off_type)newpos == (off_type)(-1)</CODE>(the positioning operation fails) the function calls<CODE>istr.<A HREF="ios.html#basic_ios::setstate">setstate</A>(failbit)</CODE>.Both functions return <CODE>*this</CODE>.</P><H3><A NAME="basic_istream::sentry"><CODE>basic_istream::sentry</CODE></A></H3><PRE>class <B>sentry</B> {public: explicit <B>sentry</B>(basic_istream& istr, bool noskip = false); <B>operator bool</B>() const; };</PRE><P>The nested class describes an object whose declaration structures the<A HREF="#formatted input functions">formatted input functions</A> and the<A HREF="#unformatted input functions">unformatted input functions</A>.If <CODE>istr.<A HREF="ios.html#basic_ios::good">good</A>()</CODE>is true, the constructor:</P><UL><LI>calls <CODE>istr.<A HREF="ios.html#basic_ios::tie">tie</A>-><A HREF="ostream.html#basic_ostream::flush">flush</A>()</CODE>if <CODE>istr.tie()</CODE> is not a null pointer</LI><LI>effectively calls <CODE><A HREF="#ws">ws</A>(istr)</CODE> if<CODE>istr.<A HREF="ios.html#ios_base::flags">flags</A>() &<A HREF="ios.html#ios_base::skipws">skipws</A></CODE> is nonzero</LI></UL><P>If, after any such preparation,<CODE>istr.good()</CODE> is false, the constructor calls<CODE>istr.<A HREF="ios.html#basic_ios::setstate">setstate</A>(failbit)</CODE>.In any case, the constructor stores the value returned by <CODE>istr.good()</CODE>in <B>status</B>.A later call to <CODE>operator bool()</CODE> delivers this stored value.</P><H3><A NAME="basic_istream::sync"><CODE>basic_istream::sync</CODE></A></H3><PRE>int <B>sync</B>();</PRE><P>If <CODE><A HREF="ios.html#basic_ios::rdbuf">rdbuf</A>()</CODE> isa null pointer, the function returns -1. Otherwise, it calls<CODE>rdbuf()-><A HREF="streambu.html#basic_streambuf::pubsync">pubsync</A>()</CODE>.If that returns -1, the function calls<CODE><A HREF="ios.html#basic_ios::setstate">setstate</A>(badbit)</CODE>and returns -1. Otherwise, the function returns zero.</P><H3><A NAME="basic_istream::tellg"><CODE>basic_istream::tellg</CODE></A></H3><PRE>pos_type <B>tellg</B>();</PRE><P>If <CODE><A HREF="ios.html#basic_ios::fail">fail</A>()</CODE> is false,the member function returns<CODE><A HREF="ios.html#basic_ios::rdbuf">rdbuf</A>()-><A HREF="streambu.html#basic_streambuf::pubseekoff">pubseekoff</A>(0,<A HREF="ios.html#ios_base::cur">cur</A>,<A HREF="ios.html#ios_base::in">in</A>)</CODE>.Otherwise, it returns <CODE>pos_type(-1)</CODE>.</P><H3><A NAME="basic_istream::unget"><CODE>basic_istream::unget</CODE></A></H3><PRE>basic_istream& <B>unget</B>();</PRE><P>The <A HREF="#unformatted input functions">unformatted input function</A>puts back the previous element in the stream, if possible, as if by calling<CODE>rdbuf()-><A HREF="streambu.html#basic_streambuf::sungetc">sungetc</A>()</CODE>.If <CODE><A HREF="ios.html#basic_ios::rdbuf">rdbuf</A>()</CODE>is a null pointer, or if the call to <CODE>sungetc</CODE> returns<CODE>traits_type::<A HREF="string2.html#char_traits::eof">eof</A>()</CODE>,the function calls<CODE><A HREF="ios.html#basic_ios::setstate">setstate</A>(badbit)</CODE>.In any case, it returns <CODE>*this</CODE>.</P><H2><A NAME="iostream"><CODE>iostream</CODE></A></H2><PRE>typedef basic_iostream<char, char_traits<char> > <B>iostream</B>;</PRE><P>The type is a synonym for template class<A HREF="#basic_iostream"><CODE>basic_iostream</CODE></A>, specializedfor elements of type <I>char</I> with default<A HREF="string2.html#character traits">character traits</A>.</P><H2><A NAME="istream"><CODE>istream</CODE></A></H2><PRE>typedef basic_istream<char, char_traits<char> > <B>istream</B>;</PRE><P>The type is a synonym for template class<A HREF="#basic_istream"><CODE>basic_istream</CODE></A>, specializedfor elements of type <I>char</I> with default<A HREF="string2.html#character traits">character traits</A>.</P><H2><A NAME="operator>>"><CODE>operator>></CODE></A></H2><PRE>template<class Elem, class Tr> basic_istream<Elem, Tr>& <B>operator>></B>(basic_istream<Elem, Tr>& istr, Elem *str);template<class Elem, class Tr> basic_istream<Elem, Tr>& <B>operator>></B>(basic_istream<Elem, Tr>& istr, Elem& ch);template<class Tr> basic_istream<char, Tr>& <B>operator>></B>(basic_istream<char, Tr>& istr, signed char *str);template<class Tr> basic_istream<char, Tr>& <B>operator>></B>(basic_istream<char, Tr>& istr, signed char& ch);template<class Tr> basic_istream<char, Tr>& <B>operator>></B>(basic_istream<char, Tr>& istr, unsigned char *str);template<class Tr> basic_istream<char, Tr>& <B>operator>></B>(basic_istream<char, Tr>& istr, unsigned char& ch);</PRE><P>The template function:</P><PRE>template<class Elem, class Tr> basic_istream<Elem, Tr>& <B>operator>></B>(basic_istream<Elem, Tr>& istr, Elem *str);</PRE><P>extracts up to <CODE>N - 1</CODE> elementsand stores them in the array beginning at <CODE>str</CODE>.If <CODE>istr.<A HREF="ios.html#ios_base::width">width</A>()</CODE> is greaterthan zero, <CODE>N</CODE> is <CODE>istr.width()</CODE>; otherwise it isthe size ofthe largest array of <CODE>Elem</CODE> that can be declared.The function always stores<CODE>Elem()</CODE> afterany extracted elements it stores. Extraction stops early on end-of-file,on a character with value <CODE>Elem(0)</CODE> (which is not extracted),or on any element (which is not extracted) that would be discarded by<CODE><A HREF="#ws">ws</A></CODE>.If the function extracts no elements, it calls<CODE>istr.<A HREF="ios.html#basic_ios::setstate">setstate</A>(failbit)</CODE>.In any case, it calls <CODE>istr.width(0)</CODE> andreturns <CODE>istr</CODE>.</P><P>The template function:</P><PRE>template<class Elem, class Tr> basic_istream<Elem, Tr>& <B>operator>></B>(basic_istream<Elem, Tr>& istr, char& ch);</PRE><P>extracts an element, if possible, and stores it in <CODE>ch</CODE>.Otherwise, it calls<CODE>is.<A HREF="ios.html#basic_ios::setstate">setstate</A>(failbit)</CODE>.In any case, it returns <CODE>istr</CODE>.</P><P>The template function:</P><PRE>template<class Tr> basic_istream<char, Tr>& <B>operator>></B>(basic_istream<char, Tr>& istr, signed char *str);</PRE><P>returns <CODE>istr >> (char *)str</CODE>.</P><P>The template function:</P><PRE>template<class Tr> basic_istream<char, Tr>& <B>operator>></B>(basic_istream<char, Tr>& istr, signed char& ch);</PRE><P>returns <CODE>istr >> (char&)ch</CODE>.</P><P>The template function:</P><PRE>template<class Tr> basic_istream<char, Tr>& <B>operator>></B>(basic_istream<char, Tr>& istr, unsigned char *str);</PRE><P>returns <CODE>istr >> (char *)str</CODE>.</P><P>The template function:</P><PRE>template<class Tr> basic_istream<char, Tr>& <B>operator>></B>(basic_istream<char, Tr>& istr, unsigned char& ch);</PRE><P>returns <CODE>istr >> (char&)ch</CODE>.</P><H2><A NAME="wiostream"><CODE>wiostream</CODE></A></H2><PRE>typedef basic_iostream<wchar_t, char_traits<wchar_t> > <B>wiostream</B>;</PRE><P>The type is a synonym for template class<A HREF="#basic_iostream"><CODE>basic_iostream</CODE></A>, specializedfor elements of type <CODE>wchar_t</CODE> with default<A HREF="string2.html#character traits">character traits</A>.</P><H2><A NAME="wistream"><CODE>wistream</CODE></A></H2><PRE>typedef basic_istream<wchar_t, char_traits<wchar_t> > <B>wistream</B>;</PRE><P>The type is a synonym for template class<A HREF="#basic_istream"><CODE>basic_istream</CODE></A>, specializedfor elements of type <CODE>wchar_t</CODE> with default<A HREF="string2.html#character traits">character traits</A>.</P><H2><A NAME="ws"><CODE>ws</CODE></A></H2><PRE>template class<Elem, Tr> basic_istream<Elem, Tr>& <B>ws</B>(basic_istream<Elem, Tr>& istr);</PRE><P>The manipulator extracts and discards any elements<CODE>ch</CODE> for which<CODE><A HREF="locale2.html#use_facet">use_facet</A><<A HREF="locale2.html#ctype">ctype</A><Elem> >(<A HREF="ios.html#ios_base::getloc">getloc</A>()).<A HREF="locale2.html#ctype::is">is</A>(ctype<Elem>::<A HREF="locale2.html#ctype_base::space">space</A>, ch)</CODE>is true.</P><P>The function calls<CODE><A HREF="ios.html#basic_ios::setstate">setstate</A>(eofbit)</CODE>if it encounters end-of-file while extracting elements.It returns <CODE>istr</CODE>.</P><HR><P>See also the<B><A HREF="index.html#Table of Contents">Table of Contents</A></B> and the<B><A HREF="_index.html">Index</A></B>.</P><P><I><A HREF="crit_pjp.html">Copyright</A> © 1992-2002by P.J. Plauger. All rights reserved.</I></P><!--V4.01:1125--></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -