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

📄 for_5394.htm

📁 C++标准库 C++标准库 C++标准库 C++标准库
💻 HTM
📖 第 1 页 / 共 3 页
字号:
<TD><SAMP>o</SAMP><BR></TD><TD>Resets the above<BR></TD><TD><SAMP>o.unsetf (ios_base::showpos)</SAMP><BR></TD></TR><TR VALIGN=top><TD><SAMP>noskipws</SAMP><BR></TD><TD><SAMP>i</SAMP><BR></TD><TD>Resets the above<BR></TD><TD><SAMP>i.unsetf(ios_base::skipws)</SAMP><BR></TD></TR><TR VALIGN=top><TD><SAMP>nounitbuf</SAMP><BR></TD><TD><SAMP>o</SAMP><BR></TD><TD>Resets the above<BR></TD><TD><SAMP>o.unsetf(ios_base::unitbuf)</SAMP><BR></TD></TR><TR VALIGN=top><TD><SAMP>nouppercase</SAMP><BR></TD><TD>&nbsp;</TD><TD>Resets the above<BR></TD><TD><SAMP>o.unsetf (ios_base::uppercase)</SAMP><BR></TD></TR><TR VALIGN=top><TD><SAMP>oct</SAMP><BR></TD><TD><SAMP>io</SAMP><BR></TD><TD>Converts to/from octal notation<BR></TD><TD><SAMP>io.setf(ios_base::oct, ios_base::basefield)</SAMP><BR></TD></TR><TR VALIGN=top><TD><SAMP>resetiosflags (ios_base::fmtflags mask)</SAMP><BR></TD><TD><SAMP>io</SAMP><BR></TD><TD>Clears <B><I><B><I>ios</I></B></B></I> flags<BR></TD><TD><SAMP>io.setf((ios_base::fmtflags)0, mask)</SAMP><BR></TD></TR><TR VALIGN=top><TD><SAMP>right</SAMP><BR></TD><TD><SAMP>o</SAMP><BR></TD><TD>Adds fill characters for adjustment to the right<BR></TD><TD><SAMP>o.setf(ios_base::right, ios_base::adjustfield)</SAMP><BR></TD></TR><TR VALIGN=top><TD><SAMP>scientific</SAMP><BR></TD><TD>&nbsp;</TD><TD>Puts floating point values in scientific notation<BR></TD><TD><SAMP>o.setf(ios_base::scientific, ios_base::floatfield)</SAMP><BR></TD></TR><TR VALIGN=top><TD><SAMP>setbase</SAMP><BR><SAMP>(int base)</SAMP><BR></TD><TD><SAMP>io</SAMP><BR></TD><TD>Sets base for integer notation (base = 8, 10, 16)<BR></TD><TD><SAMP>io.setf (base == 8?ios_base::oct: base == 10 ? <BR>ios_base::dec : base == 16 ? <BR>ios_base::hex : <BR>ios_base::fmtflags(0), <BR>ios_base::basefield)</SAMP><BR></TD></TR><TR VALIGN=top><TD><SAMP>setfill(charT c)</SAMP><BR></TD><TD><SAMP>io</SAMP><BR></TD><TD>Sets fill character for padding<BR></TD><TD><SAMP>io.fill(c)</SAMP><BR></TD></TR><TR VALIGN=top><TD><SAMP>setiosflags (ios_base::fmtflags mask)</SAMP><BR></TD><TD><SAMP>io</SAMP><BR></TD><TD>Sets <B><I><B><I>ios</I></B></B></I> flags<BR></TD><TD><SAMP>io.setf(mask)</SAMP><BR></TD></TR><TR VALIGN=top><TD><SAMP>setprecision</SAMP><BR><SAMP>(int n)</SAMP><BR></TD><TD><SAMP>io</SAMP><BR></TD><TD>Sets precision of floating point values<BR></TD><TD><SAMP>io.precision(n)</SAMP><BR></TD></TR><TR VALIGN=top><TD><SAMP>setw(int n)</SAMP><BR></TD><TD><SAMP>io</SAMP><BR></TD><TD><P><B>Sets </B>minimal field width</P><BR></TD><TD><SAMP>io.width(n)</SAMP><BR></TD></TR><TR VALIGN=top><TD><SAMP>showbase</SAMP><BR></TD><TD><SAMP>o</SAMP><BR></TD><TD>Generates a prefix indicating the numeric base of an integer<BR></TD><TD><SAMP>o.setf(ios_base::showbase)</SAMP><BR></TD></TR><TR VALIGN=top><TD><SAMP>showpoint</SAMP><BR></TD><TD><SAMP>o</SAMP><BR></TD><TD>Always generates a decimal-point for floating-point values<BR></TD><TD><SAMP>o.setf(ios_base::showpoint)</SAMP><BR></TD></TR><TR VALIGN=top><TD><SAMP>showpos</SAMP><BR></TD><TD><SAMP>o</SAMP><BR></TD><TD>Generates a <SAMP>+</SAMP> sign for non-negative numeric values<BR></TD><TD><SAMP>o.setf(ios_base::showpos)</SAMP><BR></TD></TR><TR VALIGN=top><TD><SAMP>skipws</SAMP><BR></TD><TD><SAMP>i</SAMP><BR></TD><TD>Skips leading white space <BR></TD><TD><SAMP>i.setf(ios_base::skipws)</SAMP><BR></TD></TR><TR VALIGN=top><TD><SAMP>unitbuf</SAMP><BR></TD><TD><SAMP>o</SAMP><BR></TD><TD>Flushes output after each formatting operation<BR></TD><TD><SAMP>o.setf(ios_base::unitbuf)</SAMP><BR></TD></TR><TR VALIGN=top><TD><SAMP>uppercase</SAMP><BR></TD><TD><SAMP>o</SAMP><BR></TD><TD>Replaces certain lowercase letters with their uppercase equivalents<BR></TD><TD><SAMP>o.setf(ios_base::uppercase)</SAMP><BR></TD></TR><TR VALIGN=top><TD><SAMP>ws</SAMP><BR></TD><TD><SAMP>i</SAMP><BR></TD><TD>Skips white spaces<BR></TD><TD>&nbsp;</TD></TR></TABLE></CENTER><A NAME="2.3.4"><H3>2.3.4 Localization Using the Stream's Locale</H3></A><P>Associated with each stream is a locale that impacts the parsing and formatting of numeric values.  This is how localization of software takes place.  As discussed in the section on locale, the representation of numbers often depends on cultural conventions.  In particular, the <I>decimal point</I> need not be a period, as in the following example:</P><PRE>cout.imbue(locale("De_DE"));cout &#60;&#60; 1000000.50 &#60;&#60; endl; </PRE><P>The output will be:</P><PRE>1000000,50</PRE><P>Other cultural conventions, like the grouping of digits, are irrelevant.  There is no formatting of numeric values that involves grouping.</FN><A NAME="2.3.5"><H3>2.3.5 Formatted Input</H3></A><P>In principle, input and output operators behave symmetrically.  There is only one important difference:  for output you control the precise format of the inserted character sequence, while for input the format of an extracted character sequence is never exactly described.</P><P>This is for practical reasons.  You may want to extract the next floating point value from a stream, for example, without necessarily knowing its exact format.  You want it whether it is signed or not, or in exponential notation with a small or capital E for the exponent, etc.  Hence, extractors in general accept an item in any format permitted for its type.</P><P>Formatted input is handled as follows:</P><OL><LI><P>Extractors automatically ignore all white space characters (blanks, tabulators, newlines <A HREF="endnote2.htm#fn20">[20]</A>) that precede the item to be extracted.</P></LI><LI><P>When the first relevant character is found, they extract characters from the input stream until they find a separator; that is, a character that does not belong to the item.  White space characters in particular are separators. </P></LI><LI><P>The separator remains in the input stream and becomes the first character extracted in a subsequent extraction.</P></LI></OL><P>Several format parameters, which control insertion, are irrelevant for extraction.  The format parameter fill character, <SAMP>fill()</SAMP>, and the adjustment flags, <SAMP>left</SAMP>, <SAMP>right</SAMP>, and <SAMP>internal</SAMP>, have no effect on extraction.  The field width is relevant only for extraction of strings, and ignored otherwise.</P></LI></OL><A NAME="2.3.5.1"><H4>2.3.5.1 Skipping Characters</H4></A><P>You can use the manipulator <SAMP>noskipws</SAMP> to<SAMP> </SAMP>switch off the automatic skipping of white space characters.  For example, extracting white space characters may be necessary if you expect the input has a certain format, and you need to check for violations of the format requirements.  This procedure is shown in the following code:</P><PRE>cin >> noskipws;char c;do { float fl;  c = ' '; cin >> fl >> c;  // extract number and separatorif (c == ',' || c == '\n')  // next char is ',' or newline ?    process(fl);            // yes: use the number}while (c == ',');if (c != '\n') error();     // no: error!</PRE><P>If you have to skip a sequence of characters other than white spaces, you can use the istream's member function <SAMP>ignore()</SAMP>.  The call:</P><PRE>basic_ifstream&#60;myChar,myTraits> InputStream("file-name");InputStream.ignore(numeric_limits&#60;streamsize>::max()                  ,myChar('\n'));</PRE><P>or, for ordinary tiny characters of type <SAMP>char</SAMP>: </P><PRE>ifstream InputStream("file-name");InputStream.ignore(INT_MAX,'\n');</PRE><P>ignores all characters until the end of the line.  This example uses a file stream that is not predefined.  File streams are described in <A HREF="fil_2309.htm#2.5.3">Section 2.5.3</A>.</P><A NAME="2.3.5.2"><H4>2.3.5.2 Input of Strings</H4></A><P>When you extract strings or character arrays from an input stream, characters are read until:</P><UL><LI><P>A white space character is found, or </P></LI><LI><P>The end of the input is reached, or</P></LI><LI><P>A certain number of characters are extracted, if <SAMP>width() != 0</SAMP>: In case of a string this number is the field width <SAMP>width(). </SAMP>In case of a character array  this number is <SAMP>width()-1. </SAMP></P></LI></UL><P>Note that the field width will be reset to <SAMP>0</SAMP> after the extraction of a string.</P><P>There are subtle differences between extracting a character sequence into a character array and extracting it into a string object.  For example:</P><PRE>char buf[SZ];cin >> buf;</PRE><P>is different from: </P><PRE>string s;cin >> s;</PRE><P>Extraction into a string is safe, because strings automatically extend their capacity as necessary.  You can extract as many characters as you want since the string always adjusts its size accordingly.  Character arrays, on the other hand, have fixed size and cannot dynamically extend their capacity.  If you extract more characters than the character array can take, the extractor writes beyond the end of the array.  To prevent this, you must set the field width as follows each time you extract characters into a character array:</P><PRE>char buf[SZ];cin >> width(SZ) >> buf;</PRE></LI></UL><HR><A HREF="arc_7049.htm"><IMG SRC="images/prev.gif"></A> <A HREF="booktoc2.htm"><IMG SRC="images/toc.gif"></A><A HREF="err_7848.htm"><IMG SRC="images/next.gif"></A><P>&copy;Copyright 1996, Rogue Wave Software, Inc.</P></BODY></HTML>

⌨️ 快捷键说明

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