📄 istream.html
字号:
<P>The first of these<A HREF="#unformatted input functions">unformatted input functions</A>extracts an element, if possible, as if by returning<CODE>rdbuf()-><A HREF="streambu.html#basic_streambuf::sbumpc">sbumpc</A>()</CODE>.Otherwise, it returns<CODE>traits_type::<A HREF="string2.html#char_traits::eof">eof</A>()</CODE>.If the function extracts no element, it calls<CODE><A HREF="ios.html#basic_ios::setstate">setstate</A>(failbit)</CODE>.</P><P>The second function extracts the<A HREF="ios.html#basic_ios::int_type"><CODE>int_type</CODE></A> element<CODE>meta</CODE> the same way. If <CODE>meta</CODE> compares equal to<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>(failbit)</CODE>.Otherwise, it stores<CODE>traits_type::<A HREF="string2.html#char_traits::to_char_type">to_char_type</A>(meta)</CODE>in <CODE>ch</CODE>. The function returns <CODE>*this</CODE>.</P><P>The third function returns <CODE>get(str, count, widen('\n'))</CODE>.</P><P>The fourth function extracts up to <CODE>count - 1</CODE> elementsand stores them in the array beginning at <CODE>str</CODE>. It always stores<CODE>char_type()</CODE> afterany extracted elements it stores. In order of testing, extraction stops:</P><OL><LI>at end of file</LI><LI>after the function extracts an element that compares equal to<CODE>delim</CODE>, in which case the element is put backto the controlled sequence</LI><LI>after the function extracts <CODE>count - 1</CODE> elements</LI></OL><P>If the function extracts no elements, it calls<CODE><A HREF="ios.html#basic_ios::setstate">setstate</A>(failbit)</CODE>.In any case, it returns <CODE>*this</CODE>.</P><P>The fifth function returns <CODE>get(strbuf, widen('\n'))</CODE>.</P><P>The sixth function extracts elements and inserts them in<CODE>strbuf</CODE>. Extraction stops on end-of-file or on an elementthat compares equal to <CODE>delim</CODE> (which is not extracted).It also stops, without extracting the element in question,if an insertion fails or throws an exception (which is caughtbut not rethrown). If the function extracts no elements, it calls<CODE><A HREF="ios.html#basic_ios::setstate">setstate</A>(failbit)</CODE>.In any case, the function returns <CODE>*this</CODE>.</P><H3><A NAME="basic_istream::getline"><CODE>basic_istream::getline</CODE></A></H3><PRE>basic_istream& <B>getline</B>(char_type *str, streamsize count);basic_istream& <B>getline</B>(char_type *str, streamsize count, char_type delim);</PRE><P>The first of these<A HREF="#unformatted input functions">unformatted input functions</A>returns <CODE>getline(str, count, widen('\n'))</CODE>.</P><P>The second function extracts up to <CODE>count - 1</CODE> elementsand stores them in the array beginning at <CODE>str</CODE>. It always stores<CODE>char_type()</CODE> afterany extracted elements it stores. In order of testing, extraction stops:</P><OL><LI>at end of file</LI><LI>after the function extracts an element that compares equal to<CODE>delim</CODE>, in which case the element is neither put back norappended to the controlled sequence</LI><LI>after the function extracts <CODE>count - 1</CODE> elements</LI></OL><P>If the function extracts no elements or <CODE>count - 1</CODE> elements, it calls<CODE><A HREF="ios.html#basic_ios::setstate">setstate</A>(failbit)</CODE>.In any case, it returns <CODE>*this</CODE>.</P><H3><A NAME="basic_istream::ignore"><CODE>basic_istream::ignore</CODE></A></H3><PRE>basic_istream& <B>ignore</B>(streamsize count = 1, int_type delim = traits_type::eof());</PRE><P>The <A HREF="#unformatted input functions">unformatted input function</A>extracts up to <CODE>count</CODE> elements and discards them.If <CODE>count</CODE> equals<CODE>numeric_limits<int>::<A HREF="limits2.html#numeric_limits::max">max</A>()</CODE>,however, it is taken as arbitrarily large.Extraction stops early on end-of-file oron an element <CODE>ch</CODE> such that<CODE>traits_type::<A HREF="string2.html#char_traits::to_int_type">to_int_type</A>(ch)</CODE>compares equal to <CODE>delim</CODE> (which is also extracted).The function returns <CODE>*this</CODE>.</P><H3><A NAME="basic_istream::operator>>"><CODE>basic_istream::operator>></CODE></A></H3><PRE>basic_istream& <B>operator>></B>( basic_istream& (*pfn)(basic_istream&));basic_istream& <B>operator>></B>( ios_base& (*pfn)(ios_base&));basic_istream& <B>operator>></B>( basic_ios<Elem, Tr>& (*pfn)(basic_ios<Elem, Tr>&));basic_istream& <B>operator>></B>( basic_streambuf<Elem, Tr> *strbuf);basic_istream& <B>operator>></B>(bool& val);basic_istream& <B>operator>></B>(short& val);basic_istream& <B>operator>></B>(unsigned short& val);basic_istream& <B>operator>></B>(int& val);basic_istream& <B>operator>></B>(unsigned int& val);basic_istream& <B>operator>></B>(long& val);basic_istream& <B>operator>></B>(unsigned long& val);basic_istream& <B>operator>></B>(void *& val);basic_istream& <B>operator>></B>(float& val);basic_istream& <B>operator>></B>(double& val);basic_istream& <B>operator>></B>(long double& val);</PRE><P>The first member function ensures that an expression of theform <CODE>istr >> ws</CODE> calls<CODE><A HREF="#ws">ws</A>(istr)</CODE>, then returns <CODE>*this</CODE>.The second and third functions ensure that other<A HREF="ios.html#manipulators">manipulators</A>,such as <CODE><A HREF="ios.html#hex">hex</A></CODE> behavesimilarly. The remaining functions constitute the<A HREF="#formatted input functions">formatted input functions</A>.</P><P>The function:</P><PRE>basic_istream& <B>operator>></B>( basic_streambuf<Elem, Tr> *strbuf);</PRE><P>extracts elements, if <CODE>strbuf</CODE> is not a null pointer,and inserts them in <CODE>strbuf</CODE>. Extraction stops on end-of-file.It also stops, without extracting the element in question,if an insertion fails or throws an exception (which is caughtbut not rethrown).If the function extracts no elements, it calls<CODE><A HREF="ios.html#basic_ios::setstate">setstate</A>(failbit)</CODE>.In any case, the function returns <CODE>*this</CODE>.</P><P>The function:</P><PRE>basic_istream& <B>operator>></B>(bool& val);</PRE><P>extracts a field and converts it to a boolean value by calling<CODE><A HREF="locale2.html#use_facet">use_facet</A><num_get<Elem,InIt>(<A HREF="ios.html#ios_base::getloc">getloc</A>()).<A HREF="locale2.html#num_get::get">get</A>(InIt(<A HREF="ios.html#basic_ios::rdbuf">rdbuf</A>()), Init(0), *this,getloc(), val)</CODE>. Here, <CODE>InIt</CODE> is defined as<CODE><A HREF="iterator.html#istreambuf_iterator">istreambuf_iterator</A><Elem,Tr></CODE>.The function returns <CODE>*this</CODE>.</P><P>The functions:</P><PRE>basic_istream& <B>operator>></B>(short& val);basic_istream& <B>operator>></B>(unsigned short& val);basic_istream& <B>operator>></B>(int& val);basic_istream& <B>operator>></B>(unsigned int& val);basic_istream& <B>operator>></B>(long& val);basic_istream& <B>operator>></B>(unsigned long& val);basic_istream& <B>operator>></B>(void *& val);</PRE><P>each extract a field and convert it to a numeric value by calling<CODE><A HREF="locale2.html#use_facet">use_facet</A><num_get<Elem,InIt>(<A HREF="ios.html#ios_base::getloc">getloc</A>()).<A HREF="locale2.html#num_get::get">get</A>(InIt(<A HREF="ios.html#basic_ios::rdbuf">rdbuf</A>()), Init(0), *this,getloc(), val)</CODE>. Here, <CODE>InIt</CODE> is defined as<CODE><A HREF="iterator.html#istreambuf_iterator">istreambuf_iterator</A><Elem,Tr></CODE>, and <CODE>val</CODE> has type <I>long,</I><I>unsigned long,</I> or <I>void *</I> as needed.</P><P>If the converted value cannotbe represented as the type of <CODE>val</CODE>, the function calls<CODE><A HREF="ios.html#basic_ios::setstate">setstate</A>(failbit)</CODE>.In any case, the function returns <CODE>*this</CODE>.</P><P>The functions:</P><PRE>basic_istream& <B>operator>></B>(float& val);basic_istream& <B>operator>></B>(double& val);basic_istream& <B>operator>></B>(long double& val);</PRE><P>each extract a field and convert it to a numeric value by calling<CODE><A HREF="locale2.html#use_facet">use_facet</A><num_get<Elem,InIt>(<A HREF="ios.html#ios_base::getloc">getloc</A>()).<A HREF="locale2.html#num_get::get">get</A>(InIt(<A HREF="ios.html#basic_ios::rdbuf">rdbuf</A>()), Init(0), *this,getloc(), val)</CODE>. Here, <CODE>InIt</CODE> is defined as<CODE><A HREF="iterator.html#istreambuf_iterator">istreambuf_iterator</A><Elem,Tr></CODE>, and <CODE>val</CODE> has type <I>double</I> or<I>long double</I> as needed.</P><P>If the converted value cannotbe represented as the type of <CODE>val</CODE>, the function calls<CODE><A HREF="ios.html#basic_ios::setstate">setstate</A>(failbit)</CODE>.In any case, it returns <CODE>*this</CODE>.</P><H3><A NAME="basic_istream::peek"><CODE>basic_istream::peek</CODE></A></H3><PRE>int_type <B>peek</B>();</PRE><P>The <A HREF="#unformatted input functions">unformatted input function</A>extracts an element, if possible, as if by returning<CODE>rdbuf()-><A HREF="streambu.html#basic_streambuf::sgetc">sgetc</A>()</CODE>.Otherwise, it returns<CODE>traits_type::<A HREF="string2.html#char_traits::eof">eof</A>()</CODE>.</P><H3><A NAME="basic_istream::putback"><CODE>basic_istream::putback</CODE></A></H3><PRE>basic_istream& <B>putback</B>(char_type ch);</PRE><P>The <A HREF="#unformatted input functions">unformatted input function</A>puts back <CODE>ch</CODE>, if possible, as if by calling<CODE>rdbuf()-><A HREF="streambu.html#basic_streambuf::sputbackc">sputbackc</A>()</CODE>.If <CODE><A HREF="ios.html#basic_ios::rdbuf">rdbuf</A>()</CODE>is a null pointer, or if the call to <CODE>sputbackc</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><H3><A NAME="basic_istream::read"><CODE>basic_istream::read</CODE></A></H3><PRE>basic_istream& <B>read</B>(char_type *str, streamsize count);</PRE><P>The <A HREF="#unformatted input functions">unformatted input function</A>extracts up to <CODE>count</CODE> elementsand stores them in the array beginning at <CODE>str</CODE>.Extraction stops early on end-of-file, in which case the function calls<CODE><A HREF="ios.html#basic_ios::setstate">setstate</A>(failbit)</CODE>.In any case, it returns <CODE>*this</CODE>.</P><H3><A NAME="basic_istream::readsome"><CODE>basic_istream::readsome</CODE></A></H3><PRE>streamsize <B>readsome</B>(char_type *str, streamsize count);</PRE><P>The <A HREF="#unformatted input functions">unformatted input function</A>extracts up to <CODE>count</CODE> elementsand stores them in the array beginning at <CODE>str</CODE>.If <CODE><A HREF="ios.html#basic_ios::good">good</A>()</CODE> isfalse, the function calls<CODE><A HREF="ios.html#basic_ios::setstate">setstate</A>(failbit)</CODE>.Otherwise, it assigns the value of<CODE>rdbuf()-><A HREF="streambu.html#basic_streambuf::in_avail">in_avail</A>()</CODE>to <CODE>N</CODE>. If <CODE>N < 0</CODE>, the function calls<CODE><A HREF="ios.html#basic_ios::setstate">setstate</A>(eofbit)</CODE>.Otherwise, it replaces the value stored in <CODE>N</CODE> withthe smaller of <CODE>count</CODE> and <CODE>N</CODE>, then calls<CODE><A HREF="#basic_istream::read">read</A>(str, N)</CODE>.In any case, the function returns
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -