📄 ios.html
字号:
streamsize <B><A HREF="#ios_base::width">width</A></B>() const; stramsize <B><A HREF="#ios_base::width">width</A></B>(streamsize newwidth); locale <B><A HREF="#ios_base::imbue">imbue</A></B>(const locale& loc); locale <B><A HREF="#ios_base::getloc">getloc</A></B>() const; static int <B><A HREF="#ios_base::xalloc">xalloc</A></B>(); long& <B><A HREF="#ios_base::iword">iword</A></B>(int idx); void *& <B><A HREF="#ios_base::pword">pword</A></B>(int idx); typedef void *(<B><A HREF="#ios_base::event_callback">event_callback</A></B>(event ev, ios_base& iosbase, int idx); void <B><A HREF="#ios_base::register_callback">register_callback</A></B>(event_callback pfn, int idx); static bool <B><A HREF="#ios_base::sync_with_stdio">sync_with_stdio</A></B>(bool newsync = true);protected: <B><A HREF="#ios_base::ios_base">ios_base</A></B>(); };</PRE><P>The class describes the storage and member functions common to bothinput and output streams. The class<A HREF="#ios"><CODE>ios</CODE></A> describes additionalcommon features.</P><P>An object of class <CODE>ios_base</CODE> stores<B><A NAME="formatting information">formatting information</A></B>,which consists of:</P><UL><LI><B><A NAME="format flags">format flags</A></B> in an object of type<A HREF="#ios_base::fmtflags"><CODE>fmtflags</CODE></A></LI><LI>an <B><A NAME="exception mask">exception mask</A></B> in anobject of type<A HREF="#ios_base::iostate"><CODE>iostate</CODE></A></LI><LI>a <B><A NAME="field width">field width</A></B> in an object oftype <I>int</I></LI><LI>a <B><A NAME="display precision">display precison</A></B> in anobject of type <I>int</I></LI><LI>a <B><A NAME="locale object">locale object</A></B>in an object of type<CODE><A HREF="#locale">locale</A></CODE></LI><LI>two <B><A NAME="extensible arrays">extensible arrays</A></B>,with elements of type <I>long</I> and <I>void</I> pointer</LI></UL><P>An object of class <CODE>ios_base</CODE> also stores<B><A NAME="stream state information">stream state information</A></B>,in an object of type<A HREF="#ios_base::iostate"><CODE>iostate</CODE></A>, and a<B><A NAME="callback stack">callback stack</A></B>.</P><H3><A NAME="ios_base::event"><CODE>ios_base::event</CODE></A></H3><PRE>enum <B>event</B> { <B>copyfmt_event</B>, <B>erase_event</B>, <B>imbue_event</B>};</PRE><P>The type is an enumeration that describes anobject that can store the<B><A NAME="callback event">callback event</A></B> used as an argument toa function registered with<CODE><A HREF="#ios_base::register_callback">register_callback</A></CODE>.The distinct event values are:</P><UL><LI><CODE><A NAME="ios_base::copyfmt_event">copyfmt_event</A></CODE>,to identify a callback that occurs near the end of a call to<CODE><A HREF="#ios::copyfmt">copyfmt</A></CODE>, just before the<A HREF="#exception mask">exception mask</A> is copied.</LI><LI><CODE><A NAME="ios_base::erase_event">erase_event</A></CODE>,to identify a callback that occurs at the beginning of a call to<CODE><A HREF="#ios::copyfmt">copyfmt</A></CODE>, or atthe beginning of a call to the destructor for <CODE>*this</CODE>.</LI><LI><CODE><A NAME="ios_base::imbue_event">imbue_event</A></CODE>,to identify a callback that occurs at the end of a call to<CODE><A HREF="#ios_base::imbue">imbue</A></CODE>, just before thefunction returns.</LI></UL><H3><A NAME="ios_base::event_callback"><CODE>ios_base::event_callback</CODE></A></H3><PRE>typedef void *(<B>event_callback</B>(event ev, ios_base& iosbase, int idx);</PRE><P>The type describes a pointer to a function that canbe registered with<CODE><A HREF="#ios_base::register_callback">register_callback</A></CODE>.Such a function must not throw an exception.</P><H3><A NAME="ios_base::failure"><CODE>ios_base::failure</CODE></A></H3><PRE>class <B>failure</B> : public <A HREF="exceptio.html#exception">exception</A> {public: explicit failure(const string& what_arg) { };</PRE><P>The member class serves as the base classfor all exceptions thrown by the member function<CODE><A HREF="#ios::clear">clear</A></CODE> in template class<A HREF="#ios"><CODE>ios</CODE></A>. The value returned by<CODE><A HREF="exceptio.html#exception::what">what</A>()</CODE> is<CODE>what_arg.<A HREF="string2.html#string::data">data</A>()</CODE>.</P><H3><A NAME="ios_base::flags"><CODE>ios_base::flags</CODE></A></H3><PRE>fmtflags <B>flags</B>() const;fmtflags <B>flags</B>(fmtflags newfmtflags);</PRE><P>The first member function returns the stored<A HREF="#format flags">format flags</A>. The second member functionstores <CODE>newfmtflags</CODE> in the format flags and returns its previousstored value.</P><H3><A NAME="ios_base::fmtflags"><CODE>ios_base::fmtflags</CODE></A></H3><PRE>typedef T1 <B>fmtflags</B>;static const fmtflags <B>boolalpha</B>, <B>dec</B>, <B>fixed</B>, <B>hex</B>, <B>internal</B>, <B>left</B>, <B>oct</B>, <B>right</B>, <B>scientific</B>, <B>showbase</B>, <B>showpoint</B>, <B>showpos</B>, <B>skipws</B>, <B>unitbuf</B>, <B>uppercase</B>, <B>adjustfield</B>, <B>basefield</B>, <B>floatfield</B>;</PRE><P>The type is a <A HREF="lib_cpp.html#bitmask type">bitmask type</A><CODE>T1</CODE> that describes an object that can store<A HREF="#format flags">format flags</A>. The distinct flag values (elements) are:</P><UL><LI><CODE><A NAME="ios_base::boolalpha">boolalpha</A></CODE>, to insert orextract objects of type <I>bool</I> as names (such as <CODE>true</CODE>and <CODE>false</CODE>) rather than as numeric values</LI><LI><CODE><A NAME="ios_base::dec">dec</A></CODE>, to insert or extractinteger values in decimal format</LI><LI><CODE><A NAME="ios_base::fixed">fixed</A></CODE>, to insertfloating-point values in fixed-point format (with no exponent field)</LI><LI><CODE><A NAME="ios_base::hex">hex</A></CODE>, to insert or extractinteger values in hexadecimal format</LI><LI><CODE><A NAME="ios_base::internal">internal</A></CODE>,to pad to a <A HREF="#field width">field width</A>as needed by inserting <A HREF="#fill character">fillcharacters</A> at a point internal to a generated numeric field</LI><LI><CODE><A NAME="ios_base::left">left</A></CODE>,to pad to a <A HREF="#field width">field width</A> as neededby inserting <A HREF="#fill character">fill characters</A>at the end of a generated field (left justification)</LI><LI><CODE><A NAME="ios_base::oct">oct</A></CODE>, to insert or extractinteger values in octal format</LI><LI><CODE><A NAME="ios_base::right">right</A></CODE>,to pad to a <A HREF="#field width">field width</A>as needed by inserting <A HREF="#fill character">fill characters</A>at the beginning of a generated field (right justification)</LI><LI><CODE><A NAME="ios_base::scientific">scientific</A></CODE>, to insertfloating-point values in scientific format (with an exponent field)</LI><LI><CODE><A NAME="ios_base::showbase">showbase</A></CODE>, to insert aprefix that reveals the base of a generated integer field</LI><LI><CODE><A NAME="ios_base::showpoint">showpoint</A></CODE>, to insert adecimal point unconditionally in a generated floating-point field</LI><LI><CODE><A NAME="ios_base::showpos">showpos</A></CODE>, to insert a plussign in a non-negative generated numeric field</LI><LI><CODE><A NAME="ios_base::skipws">skipws</A></CODE>, to skip leading<A HREF="lib_prin.html#white space">white space</A> before certainextractions</LI><LI><CODE><A NAME="ios_base::unitbuf">unitbuf</A></CODE>, to flush outputafter each insertion</LI><LI><CODE><A NAME="ios_base::uppercase">uppercase</A></CODE>, to insertuppercase equivalents of lowercase letters in certain insertions</LI></UL><P>In addition, several useful values are:</P><UL><LI><CODE><A NAME="ios_base::adjustfield">adjustfield</A></CODE>,<CODE>internal | left | right</CODE></LI><LI><CODE><A NAME="ios_base::basefield">basefield</A></CODE>,<CODE>dec | hex | oct</CODE></LI><LI><CODE><A NAME="ios_base::floatfield">floatfield</A></CODE>,<CODE>fixed | scientific</CODE></LI></UL><H3><A NAME="ios_base::getloc"><CODE>ios_base::getloc</CODE></A></H3><PRE>locale <B>getloc</B>() const;</PRE><P>The member function returns the storedlocale object.</P><H3><A NAME="ios_base::imbue"><CODE>ios_base::imbue</CODE></A></H3><PRE>locale <B>imbue</B>(const locale& loc);</PRE><P>The member function stores <CODE>loc</CODE> in thelocale object, then reports the<A HREF="#callback event">callback event</A><CODE><A HREF="#ios_base::imbue_event">imbue_event</A></CODE>.It returns the previous stored value.</P><H3><A NAME="ios_base::Init"><CODE>ios_base::Init</CODE></A></H3><PRE>class <B>Init</B> { };</PRE><P>The nested class describes an object whose construction ensures thatthe standard iostreams objects are properly<A HREF="iostream.html#constructing iostreams">constructed</A>, evenbefore the execution of a constructor for an arbitrary static object.</P><H3><A NAME="ios_base::ios_base"><CODE>ios_base::ios_base</CODE></A></H3><PRE><B>ios_base</B>();</PRE><P>The (protected) constructor does nothing. A later call to<CODE>ios::<A HREF="#ios::init">init</A></CODE><I>must</I> initialize the object before it can be safely destroyed.Thus, the only safe use for class <CODE>ios_base</CODE> is as a baseclass for template class<CODE><A HREF="#ios">ios</A></CODE>.</P><H3><A NAME="ios_base::iostate"><CODE>ios_base::iostate</CODE></A></H3><PRE>typedef T2 <B>iostate</B>;static const iostate <B>badbit</B>, <B>eofbit</B>, <B>failbit</B>, <B>goodbit</B>;</PRE><P>The type is a <A HREF="lib_cpp.html#bitmask type">bitmask type</A><CODE>T2</CODE> that describes an object that can store<A HREF="#stream state information">stream state information</A>. Thedistinct flag values (elements) are:</P><UL><LI><CODE><A NAME="ios_base::badbit">badbit</A></CODE>, to record a loss ofintegrity of the stream buffer</LI><LI><CODE><A NAME="ios_base::eofbit">eofbit</A></CODE>, to recordend-of-file while extracting from a stream</LI><LI><CODE><A NAME="ios_base::failbit">failbit</A></CODE>, to record afailure to extract a valid field from a stream</LI></UL><P>In addition, a useful value is:</P><UL><LI><CODE><A NAME="ios_base::goodbit">goodbit</A></CODE>, no bits set</LI></UL><H3><A NAME="ios_base::iword"><CODE>ios_base::iword</CODE></A></H3><PRE>long& <B>iword</B>(int idx);</PRE><P>The member function returns a reference to element<CODE>idx</CODE> of the<A HREF="#extensible arrays">extensible array</A> with elements of type<I>long.</I> All elements are effectively present and initially storethe value zero. The returned reference is invalid after the next call to<CODE>iword</CODE> for the object, after the object is altered by a call to<CODE>ios::<A HREF="#ios::copyfmt">copyfmt</A></CODE>, orafter the object is destroyed.</P><P>If <CODE>idx</CODE> is negative, or if unique storage is unavailablefor the element, the function calls<CODE><A HREF="#ios::setstate">setstate</A>(badbit)</CODE>and returns a reference that might not be unique.</P><P>To obtain a unique index, for use across all objects of type<CODE>ios_base</CODE>, call<CODE><A HREF="#ios_base::xalloc">xalloc</A></CODE>.</P><H3><A NAME="ios_base::openmode"><CODE>ios_base::openmode</CODE></A></H3><PRE>typedef T3 <B>openmode</B>;static const openmode <B>app</B>, <B>ate</B>, <B>binary</B>, <B>in</B>, <B>out</B>, <B>trunc</B>;</PRE><P>The type is a <A HREF="lib_cpp.html#bitmask type">bitmask type</A><CODE>T3</CODE> that describes an object that can store the<B><A NAME="opening mode">opening mode</A></B> for several iostreamsobjects. The distinct flag values (elements) are:</P><UL><LI><CODE><A NAME="ios_base::app">app</A></CODE>, to seek to the end of astream before each insertion</LI><LI><CODE><A NAME="ios_base::ate">ate</A></CODE>, to seek to the end of astream when its controlling object is first created</LI><LI><CODE><A NAME="ios_base::binary">binary</A></CODE>, to read a file as a<A HREF="lib_file.html#binary stream">binary stream</A>,rather than as a<A HREF="lib_file.html#text stream">text stream</A></LI><LI><CODE><A NAME="ios_base::in">in</A></CODE>,to permit extraction from a stream</LI><LI><CODE><A NAME="ios_base::out">out</A></CODE>,to permit insertion to a stream</LI><LI><CODE><A NAME="ios_base::trunc">trunc</A></CODE>, to truncate anexisting file when its controlling object is first created</LI></UL><H3><A NAME="ios_base::operator="><CODE>ios_base::operator=</CODE></A></H3><PRE>ios_base& <B>operator=</B>(const ios_base& right);</PRE><P>The operator copies the stored<A HREF="#formatting information">formatting information</A>,making a new copy of any<A HREF="#extensible arrays">extensible arrays</A>.It then returns <CODE>*this</CODE>. Note that the<A HREF="#callback stack">callback stack</A> is <I>not</I> copied.</P><H3><A NAME="ios_base::precision"><CODE>ios_base::precision</CODE></A></H3><PRE>streamsize <B>precision</B>() const;streamsize <B>precision</B>(streamsize newprecision);</PRE><P>The first member function returns the stored<A HREF="#display precision">display precision</A>. The second memberfunction stores <CODE>newprecision</CODE> in the display precision and returnsits previous stored value.</P><H3><A NAME="ios_base::pword"><CODE>ios_base::pword</CODE></A></H3>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -