亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? ch16.htm

?? good book for learning c++ standard language
?? HTM
?? 第 1 頁 / 共 5 頁
字號:
<P>At times you want to ignore the remaining characters on a line until you hit either
end of line (EOL) or end of file (EOF). The member function <TT>ignore()</TT> serves
this purpose. <TT>ignore()</TT> takes two parameters, the maximum number of characters
to ignore and the termination character. If you write <TT>ignore(80,'\n')</TT>, up
to 80 characters will be thrown away until a newline character is found. The newline
is then thrown away and the <TT>ignore()</TT> statement ends. Listing 16.8 illustrates
the use of <TT>ignore()</TT>.</P>
<P><A NAME="Heading33"></A><FONT SIZE="4" COLOR="#000077"><B>Listing 16.8. Using
ignore().</B></FONT></P>
<PRE><FONT COLOR="#0066FF">1:     // Listing 16.8 - Using ignore()
2:     #include &lt;iostream.h&gt;
3:
4:     int main()
5:     {
6:        char stringOne[255];
7:        char stringTwo[255];
8:
9:        cout &lt;&lt; &quot;Enter string one:&quot;;
10:       cin.get(stringOne,255);
11:       cout &lt;&lt; &quot;String one&quot; &lt;&lt; stringOne &lt;&lt; endl;
12:
13:       cout &lt;&lt; &quot;Enter string two: &quot;;
14:       cin.getline(stringTwo,255);
15:       cout &lt;&lt; &quot;String two: &quot; &lt;&lt; stringTwo &lt;&lt; endl;
16:
17:       cout &lt;&lt; &quot;\n\nNow try again...\n&quot;;
18:
19:       cout &lt;&lt; &quot;Enter string one: &quot;;
20:       cin.get(stringOne,255);
21:       cout &lt;&lt; &quot;String one: &quot; &lt;&lt; stringOne&lt;&lt; endl;
22:
23:       cin.ignore(255,'\n');
24:
25:       cout &lt;&lt; &quot;Enter string two: &quot;;
26:       cin.getline(stringTwo,255);
27:       cout &lt;&lt; &quot;String Two: &quot; &lt;&lt; stringTwo&lt;&lt; endl;
28:     return 0;
<TT>29: }</TT></FONT>
<FONT COLOR="#0066FF">
Output: Enter string one:once upon a time
String oneonce upon a time
Enter string two: String two:

Now try again...
Enter string one: once upon a time
String one: once upon a time
Enter string two: there was a
String Two: there was a</FONT></PRE>
<P><FONT COLOR="#000077"><B>Analysis</B></FONT><FONT COLOR="#000000"><B>: </B></FONT>On
lines 6 and 7, two character arrays are created. On line 9, the user is prompted
for input and types <TT>once upon a time</TT>, followed by Enter. On line 10, <TT>get()</TT>
is used to read this string. <TT>get()</TT> fills <TT>stringOne</TT> and terminates
on the newline, but leaves the newline character in the input buffer.</P>
<P>On line 13, the user is prompted again, but the <TT>getline()</TT> on line 14
reads the newline that is already in the buffer and terminates immediately, before
the user can enter any input.</P>
<P>On line 19, the user is prompted again and puts in the same first line of input.
This time, however, on line 23, <TT>ignore()</TT> is used to &quot;eat&quot; the
newline character. Thus, when the <TT>getline()</TT> call on line 26 is reached,
the input buffer is empty, and the user can input the next line of the story.
<H4 ALIGN="CENTER"><A NAME="Heading34"></A><FONT COLOR="#000077">peek() and putback()</FONT></H4>
<P>The input object <TT>cin</TT> has two additional methods that can come in rather
handy: <TT>peek()</TT>, which looks at but does not extract the next character, and
<TT>putback()</TT>, which inserts a character into the input stream. Listing 16.9
illustrates how these might be used.</P>
<P><A NAME="Heading35"></A><FONT SIZE="4" COLOR="#000077"><B>Listing 16.9. Using
peek() and putback().</B></FONT></P>
<PRE><FONT COLOR="#0066FF">1:     // Listing 16.9 - Using peek() and putback()
2:     #include &lt;iostream.h&gt;
3:
4:     int main()
5:     {
6:        char ch;
7:        cout &lt;&lt; &quot;enter a phrase: &quot;;
8:        while ( cin.get(ch) )
9:        {
10:          if (ch == `!')
11:             cin.putback(`$');
12:          else
13:             cout &lt;&lt; ch;
14:          while (cin.peek() == `#')
15:             cin.ignore(1,'#');
16:       }
17:     return 0;
<TT>18: }</TT></FONT>
<FONT COLOR="#0066FF">
Output: enter a phrase: Now!is#the!time#for!fun#!
Now$isthe$timefor$fun$
</FONT></PRE>
<P><FONT COLOR="#000077"><B>Analysis</B></FONT><FONT COLOR="#000000"><B>: </B></FONT>On
line 6, a character variable, <TT>ch</TT>, is declared, and on line 7, the user is
prompted to enter a phrase. The purpose of this program is to turn any exclamation
marks (<TT>!</TT>) into dollar signs (<TT>$</TT>) and to remove any pound symbols
(<TT>#</TT>).</P>
<P>The program loops as long as it is getting characters other than the end of file
(remember that <TT>cin.get()</TT> returns <TT>0</TT> for end of file). If the current
character is an exclamation point, it is thrown away and the <TT>$</TT> symbol is
put back into the input buffer; it will be read the next time through. If the current
item is not an exclamation point, it is printed. The next character is &quot;peeked&quot;
at, and when pound symbols are found, they are removed.</P>
<P>This is not the most efficient way to do either of these things (and it won't
find a pound symbol if it is the first character), but it does illustrate how these
methods work. They are relatively obscure, so don't spend a lot of time worrying
about when you might really use them. Put them into your bag of tricks; they'll come
in handy sooner or later.


<BLOCKQUOTE>
	<P>
<HR>
<FONT COLOR="#000077"><TT><B>TIP:</B></TT></FONT><TT><B> </B>peek()</TT> and <TT>putback()</TT>
	are typically used for parsing strings and other data, such as when writing a compiler.
	
<HR>


</BLOCKQUOTE>

<H3 ALIGN="CENTER"><A NAME="Heading36"></A><FONT COLOR="#000077">Output with cout</FONT></H3>
<P>You have used <TT>cout</TT> along with the overloaded insertion operator (<TT>&lt;&lt;</TT>)
to write strings, integers, and other numeric data to the screen. It is also possible
to format the data, aligning columns and writing the numeric data in decimal and
hexadecimal. This section will show you how.
<H4 ALIGN="CENTER"><A NAME="Heading37"></A><FONT COLOR="#000077">Flushing the Output</FONT></H4>
<P>You've already seen that using <TT>endl</TT> will flush the output buffer. <TT>endl</TT>
calls <TT>cout</TT>'s member function <TT>flush()</TT>, which writes all of the data
it is buffering. You can call the <TT>flush()</TT> method directly, either by calling
the <TT>flush()</TT> member method or by writing the following:</P>
<PRE><FONT COLOR="#0066FF">cout &lt;&lt; flush
</FONT></PRE>
<P>This can be convenient when you need to ensure that the output buffer is emptied
and that the contents are written to the screen.
<H3 ALIGN="CENTER"><A NAME="Heading38"></A><FONT COLOR="#000077">Related Functions</FONT></H3>
<P>Just as the extraction operator can be supplemented with <TT>get()</TT> and <TT>getline()</TT>,
the insertion operator can be supplemented with <TT>put()</TT> and <TT>write()</TT>.</P>
<P>The function <TT>put()</TT> is used to write a single character to the output
device. Because <TT>put()</TT> returns an <TT>ostream</TT> reference, and because
<TT>cout</TT> is an <TT>ostream</TT> object, you can concatenate <TT>put()</TT> just
as you do the insertion operator. Listing 16.10 illustrates this idea.</P>
<P><A NAME="Heading39"></A><FONT SIZE="4" COLOR="#000077"><B>Listing 16.10. Using
put().</B></FONT></P>
<PRE><FONT COLOR="#0066FF">1:     // Listing 16.10 - Using put()
2:     #include &lt;iostream.h&gt;
3:
4:     int main()
5:     {
6:        cout.put(`H').put(`e').put(`l').put(`l').put(`o').put(`\n');
7:     return 0;
<TT>8: }</TT>
Output: Hello
</FONT></PRE>
<P><FONT COLOR="#000077"><B>Analysis</B></FONT><FONT COLOR="#000000"><B>:</B></FONT><B>
</B>Line 6 is evaluated like this: <TT>cout.put(`H')</TT> writes the letter <TT>H</TT>
to the screen and returns the <TT>cout</TT> object. This leaves the following:</P>
<PRE><FONT COLOR="#0066FF">cout.put(`e').put(`l').put(`l').put(`o').put(`\n');</FONT></PRE>
<P>The letter <TT>e</TT> is written, leaving <TT>cout.put(`l')</TT>. This process
repeats, each letter being written and the <TT>cout</TT> object returned until the
final character (<TT>`\n'</TT>) is written and the function returns.</P>
<P>The function <TT>write()</TT> works just like the insertion operator (<TT>&lt;&lt;</TT>),
except that it takes a parameter that tells the function the maximum number of characters
to write. Listing 16.11 illustrates its use.</P>
<P><A NAME="Heading40"></A><FONT SIZE="4" COLOR="#000077"><B>Listing 16.11. Using
write().</B></FONT></P>
<PRE><FONT COLOR="#0066FF">1:     // Listing 16.11 - Using write()
2:     #include &lt;iostream.h&gt;
3:     #include &lt;string.h&gt;
4:
5:     int main()
6:     {
7:        char One[] = &quot;One if by land&quot;;
8:
9:
10:
11:       int fullLength = strlen(One);
12:       int tooShort = fullLength -4;
13:       int tooLong = fullLength + 6;
14:
15:       cout.write(One,fullLength) &lt;&lt; &quot;\n&quot;;
16:       cout.write(One,tooShort) &lt;&lt; &quot;\n&quot;;
17:       cout.write(One,tooLong) &lt;&lt; &quot;\n&quot;;
18:     return 0;
<TT>19: }</TT></FONT>
<FONT COLOR="#0066FF">
Output: One if by land
One if by
One if by land i?!
</FONT></PRE>


<BLOCKQUOTE>
	<P>
<HR>
<FONT COLOR="#000077"><B>NOTE:</B></FONT><B> </B>The last line of output may look
	different on your computer. 
<HR>


</BLOCKQUOTE>

<P><FONT COLOR="#000077"><B>Analysis</B></FONT><FONT COLOR="#000000"><B>: </B></FONT>On
line 7, one phrase is created. On line 11, the integer <TT>fullLength</TT> is set
to the length of the phrase and <TT>tooShort</TT> is set to that length minus four,
while <TT>tooLong</TT> is set to <TT>fullLength</TT> plus six.</P>
<P>On line 15, the complete phrase is printed using <TT>write()</TT>. The length
is set to the actual length of the phrase, and the correct phrase is printed.</P>
<P>On line 16, the phrase is printed again, but is four characters shorter than the
full phrase, and that is reflected in the output.</P>
<P>On line 17, the phrase is printed again, but this time <TT>write()</TT> is instructed
to write an extra six characters. Once the phrase is written, the next six bytes
of contiguous memory are written.
<H3 ALIGN="CENTER"><A NAME="Heading41"></A><FONT COLOR="#000077">Manipulators, Flags,
and Formatting Instructions</FONT></H3>
<P>The output stream maintains a number of state flags, determining which base (decimal
or hexadecimal) to use, how wide to make the fields, and what character to use to
fill in fields. A state flag is just a byte whose individual bits are each assigned
a special meaning. Manipulating bits in this way is discussed on Day 21. Each of
<TT>ostream</TT>'s flags can be set using member functions and manipulators.
<H4 ALIGN="CENTER"><A NAME="Heading42"></A><FONT COLOR="#000077">Using cout.width()</FONT></H4>
<P>The default width of your output will be just enough space to print the number,
character, or string in the output buffer. You can change this by using <TT>width()</TT>.
Because <TT>width()</TT> is a member function, it must be invoked with a <TT>cout</TT>
object. It only changes the width of the very next output field and then immediately
reverts to the default. Listing 16.12 illustrates its use.</P>
<P><A NAME="Heading43"></A><FONT SIZE="4" COLOR="#000077"><B>Listing 16.12. Adjusting
the width of output.</B></FONT></P>
<PRE><FONT COLOR="#0066FF">1:     // Listing 16.12 - Adjusting the width of output
2:     #include &lt;iostream.h&gt;
3:
4:     int main()
5:     {
6:        cout &lt;&lt; &quot;Start &gt;&quot;;
7:        cout.width(25);
8:        cout &lt;&lt; 123 &lt;&lt; &quot;&lt; End\n&quot;;
9:
10:       cout &lt;&lt; &quot;Start &gt;&quot;;
11:       cout.width(25);
12:       cout &lt;&lt; 123&lt;&lt; &quot;&lt; Next &gt;&quot;;
13:       cout &lt;&lt; 456 &lt;&lt; &quot;&lt; End\n&quot;;
14:
15:       cout &lt;&lt; &quot;Start &gt;&quot;;
16:       cout.width(4);
17:       cout &lt;&lt; 123456 &lt;&lt; &quot;&lt; End\n&quot;;
18:
19:     return 0;
<TT>20: }</TT></FONT>
<FONT COLOR="#0066FF">
Output: Start &gt;                  123&lt; End
Start &gt;                  123&lt; Next &gt;456&lt; End
Start &gt;123456&lt; End
</FONT></PRE>
<P><FONT COLOR="#000077"><B>Analysis</B></FONT><FONT COLOR="#000000"><B>:</B></FONT><B>
</B>The first output, on lines 6-8, prints the number 123 within a field whose width
is set to 25 on line 7. This is reflected in the first line of output.</P>
<P>The second line of output first prints the value 123 in the same field whose width
is set to 25, and then prints the value 456. Note that 456 is printed in a field
whose width is reset to just large enough; as stated, the effect of <TT>width()</TT>

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
午夜电影久久久| 在线免费精品视频| 欧美成人欧美edvon| 精品写真视频在线观看| 欧美精品日日鲁夜夜添| 亚洲3atv精品一区二区三区| 91久久精品一区二区三| 一区二区三区四区精品在线视频| 欧美日韩一区二区三区四区| 亚洲影院理伦片| 欧美精品在线观看播放| 久久精品免费看| 久久久久久久久久电影| 91丨porny丨首页| 日日欢夜夜爽一区| 日韩无一区二区| 成人激情开心网| 亚洲国产精品久久久久秋霞影院| 欧美成人精品高清在线播放 | 欧美三片在线视频观看 | 国产精品乱人伦| 色先锋aa成人| 国产精品一区二区三区乱码| 亚洲黄色尤物视频| 精品999在线播放| 欧美亚洲动漫另类| 国产久卡久卡久卡久卡视频精品| 亚洲夂夂婷婷色拍ww47| 国产亲近乱来精品视频| 欧美酷刑日本凌虐凌虐| 丰满亚洲少妇av| 国产又黄又大久久| 天天av天天翘天天综合网色鬼国产 | 亚洲欧洲av在线| 国产午夜一区二区三区| 欧美精品自拍偷拍| 在线看日本不卡| 成人黄动漫网站免费app| 蜜臀av一区二区三区| 亚洲国产精品视频| 亚洲一区二区三区国产| 亚洲人成精品久久久久| 国产精品免费丝袜| 久久久久久97三级| 久久亚洲二区三区| 久久久久久久久一| 日韩精品最新网址| 精品国产91洋老外米糕| 日韩精品一区二区三区蜜臀| 欧美大片日本大片免费观看| 日韩一区和二区| 欧美成人vr18sexvr| 久久久久久亚洲综合影院红桃 | 国产精品三级av在线播放| 99re成人精品视频| 成人aaaa免费全部观看| 色综合色狠狠综合色| 欧美日韩国产综合草草| 日韩精品一区二区三区四区视频| 26uuuu精品一区二区| 中文字幕在线观看一区二区| 亚洲天堂福利av| 五月婷婷综合网| 国内精品自线一区二区三区视频| 粉嫩aⅴ一区二区三区四区五区 | 成人av网在线| 777欧美精品| 国产视频一区不卡| 丝袜a∨在线一区二区三区不卡| 国模无码大尺度一区二区三区| 成人性生交大片免费看中文 | 国产精品2024| 91免费小视频| 久久在线观看免费| 亚洲国产综合91精品麻豆| 国产尤物一区二区| 欧美肥妇free| 亚洲美女免费在线| 国产乱淫av一区二区三区| 欧美网站大全在线观看| 中文字幕成人av| 久久国产精品72免费观看| 91激情五月电影| 亚洲美腿欧美偷拍| 国产一区二区在线看| 91精品国产麻豆国产自产在线| 亚洲欧美在线aaa| 国产成人免费视频一区| 日韩免费性生活视频播放| 午夜精品免费在线| 欧美精品第1页| 国产伦精品一区二区三区视频青涩 | 精品亚洲aⅴ乱码一区二区三区| 欧美色网站导航| 亚洲一区二区在线免费观看视频 | 久久精品亚洲精品国产欧美| 韩国一区二区在线观看| 91精品国产91久久久久久一区二区 | 亚洲国产精品久久人人爱| 色婷婷综合久色| 尤物av一区二区| 在线亚洲一区观看| 五月婷婷色综合| 精品日韩成人av| 国产电影精品久久禁18| 国产精品久线在线观看| 91麻豆国产精品久久| 亚洲aaa精品| 久久精品欧美一区二区三区不卡| 成人午夜碰碰视频| 亚洲最新视频在线观看| 欧美一级二级三级蜜桃| 99久久伊人精品| 麻豆91精品视频| 综合婷婷亚洲小说| 日韩手机在线导航| av电影在线观看不卡 | 亚洲欧洲日产国码二区| 91精品中文字幕一区二区三区| 精品一区二区三区久久| 亚洲永久免费av| 久久中文娱乐网| 欧美一区午夜视频在线观看| 国产成人精品免费网站| 天天综合色天天综合色h| 成人18视频日本| 久久精品国产77777蜜臀| 亚洲视频网在线直播| 亚洲人成亚洲人成在线观看图片| 久久午夜电影网| 日韩一区二区三区免费观看| 欧美色涩在线第一页| 成人a免费在线看| 国产成人精品免费看| 韩国一区二区视频| 蜜桃久久精品一区二区| 视频一区二区三区中文字幕| 一二三区精品福利视频| 国产精品国产三级国产aⅴ中文| 欧美成人猛片aaaaaaa| 欧美精品日韩精品| 欧美美女一区二区| 欧美日韩一区二区三区四区五区| 成人国产精品免费观看动漫 | 亚洲国产精品一区二区尤物区| 亚洲日本va在线观看| 亚洲私人黄色宅男| 自拍偷拍亚洲激情| 中文字幕不卡在线| 亚洲欧洲精品天堂一级| 日韩一区欧美一区| 亚洲国产成人午夜在线一区| 国产精品欧美一区喷水| 国产精品福利一区二区三区| 国产精品久久久久婷婷二区次| 久久精品日韩一区二区三区| 欧美激情艳妇裸体舞| 亚洲人吸女人奶水| 日韩综合一区二区| 国产在线一区观看| 91麻豆国产福利在线观看| 欧美精品高清视频| 久久精品男人天堂av| 亚洲欧美精品午睡沙发| 美国欧美日韩国产在线播放| 国产裸体歌舞团一区二区| 精品日本一线二线三线不卡| 国产精品久久久久久久第一福利| 亚洲激情欧美激情| 国产一区二区0| 欧美日高清视频| 久久久久久久av麻豆果冻| 依依成人精品视频| 久久精品一区四区| 午夜伊人狠狠久久| 99精品视频一区二区| 久久色视频免费观看| 国产精品亚洲一区二区三区在线| 92精品国产成人观看免费| 日韩欧美视频在线| 午夜精品久久久久久久久久久 | 人人精品人人爱| 色婷婷av一区二区三区gif | 亚洲欧美日韩综合aⅴ视频| 日本不卡1234视频| 欧美日韩精品二区第二页| 午夜视频在线观看一区| 欧美影片第一页| 亚洲一区视频在线观看视频| 一本大道久久a久久精品综合| 国产精品女上位| 91国偷自产一区二区使用方法| 中文字幕精品—区二区四季| 国产成人亚洲综合a∨猫咪| 日韩欧美色综合| 成人av网站在线| 图片区小说区区亚洲影院| 欧美成人精品高清在线播放| 懂色av一区二区在线播放| 亚洲日本va午夜在线电影|