freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

第14章輸入輸出與文件-文庫吧

2025-08-25 16:35 本頁面


【正文】 {int grade, highestGrade = 1。 cout Enter grade (enter endoffile to end): 。 while ( cin grade) { if ( grade highestGrade) highestGrade = grade。 cout Enter grade (enter endoffile to end): 。 } cout \n\nHighest grade is: highestGrade endl。 return 0。 } 《 程序設(shè)計 》 程序設(shè)計 24 輸出結(jié)果: Enter grade (enter endoffile to end): 67 Enter grade (enter endoffile to end): 87 Enter grade (enter end of file to end): 73 Enter grade (enter endoffile to end): 95 Enter grade (enter endoffile to end): 34 Enter grade (enter endoffile to end): 99 Entergrade (enter endoffile to end): ^ z Heighest grade is: 99 《 程序設(shè)計 》 程序設(shè)計 25 成員函數(shù) get ? Get函數(shù)用于讀入字符或字符串 ? get函數(shù)有三種格式: ?不帶參數(shù) ?帶一個參數(shù) ?帶三個參數(shù) 《 程序設(shè)計 》 程序設(shè)計 26 不帶參數(shù)的 get函數(shù) ? 不帶參數(shù)的 get函數(shù)從當(dāng)前對象讀入一個字符,包括空白字符以及表示文件結(jié)束的 EOF,并將讀入值作為函數(shù)的返回值返回。如下列語句 while((ch = ()) !=EOF) cout ch。 將輸入的字符回顯在顯示器上,直到輸入 EOF。 《 程序設(shè)計 》 程序設(shè)計 27 include iostream Using namespace std。 int main() { char c。 while ( ( c = () ) != EOF ) ( c )。 cout \nEOF in this system is: c。 return 0。 } 《 程序設(shè)計 》 程序設(shè)計 28 輸出結(jié)果: Enter a sentence followed by endoffile: Testing the get and put member functions^z Testing the get and put member functions EOF in this system is: 1 《 程序設(shè)計 》 程序設(shè)計 29 帶一個參數(shù)的 get函數(shù) 例如,下面的循環(huán)語句將輸入一個字符串,存入字符數(shù)組 ch,直到輸入回車。 (ch[0])。 for (i = 0。 ch[i] != 39。\n39。 ++i) (ch[i+1])。 ch[i] = 39。\039。 ? 帶一個字符類型的引用參數(shù),它將輸入流中的下一字符(包括空白字符)存儲在參數(shù)中,它的返回值是當(dāng)前對象的引用。 《 程序設(shè)計 》 程序設(shè)計 30 帶有三個參數(shù)的 get成員函數(shù) ? 參數(shù)分別是接收字符的字符數(shù)組、字符數(shù)組的大小和分隔符 (默認(rèn)值為‘ \n’)。 ? 函數(shù)或者在讀取比指定的最大字符數(shù)少一個字符后結(jié)束,或者在遇到分隔符時結(jié)束。 ? 為使字符數(shù)組 (被程序用作緩沖區(qū) )中的輸入字符串能夠結(jié)束,空字符會被插入到字符數(shù)組中。函數(shù)不把分隔符放到字符數(shù)組中,但是分隔符仍然會保留在輸入流中。 《 程序設(shè)計 》 程序設(shè)計 31 ? 要輸入一行字符,可用下列語句: (ch, 80, ’\n’)。 或 (ch, 80)。 ? 要輸入一個以句號結(jié)尾的句子,可用下面的語句: (ch, 80, ’.’)。 ? 當(dāng)遇到輸入結(jié)束符時,程序插入一個’ \0’作為輸入字符串的結(jié)束標(biāo)記,輸入結(jié)束符沒有放在字符數(shù)組中,而是保留在輸入流中,下一個和輸入相關(guān)的語句會讀入這個輸入結(jié)束符。如對應(yīng)于語句 (ch, 80, ’.’)。 用戶輸入 abcdef.↙ 則 ch中保存的是字符串“ abcdef”,而“ .”仍保留在輸入緩沖區(qū)中。如果繼續(xù)調(diào)用 (ch1)。 或 cin ch1 。 則字符變量 ch1中保存的是“ .”。 《 程序設(shè)計 》 程序設(shè)計 32 include iostream Using namespace std。 int main() { const int SIZE = 80。 char buffer1[ SIZE ], buffer2[ SIZE ] 。 cout Enter a sentence:\n。 cin buffer1。 cout \nThe string read with cin was:\n buffer1 n\n。 ( buffer2, SIZE )。 cout The string read with was:\n buffer2 endl。 return 0。 } 《 程序設(shè)計 》 程序設(shè)計 33 輸出結(jié)果: Enter a sentence: Contrasting string input with cin and The string read with cin was: Contrasting The string read with was: string input with cin and 《 程序設(shè)計 》 程序設(shè)計 34 成員函數(shù) getline 與帶三個參數(shù)的 get函數(shù)類似,它讀取一行信息到字符數(shù)組中,然后插入一個空字符。所不同的是, getline要去除輸入流中的分隔符 (即讀取字符并刪除它 ),但是不把它存放在字符數(shù)組中。 《 程序設(shè)計 》 程序設(shè)計 35 include iostream Using namespace std。 int main() { const SIZE = 80。 char buffe[ SIZE ]。 cout Enter a sentence:\n。 ( buffer, SIZE )。 cout \nThe sentence entered is:\n buffer endl。 return 0。 } 《 程序設(shè)計 》 程序設(shè)計 36 輸出結(jié)果: Enter a sentence: Using the getline member function The sentence entered is: Using the getline member function 《 程序設(shè)計 》 程序設(shè)計 37 用 Read函數(shù)輸入 ? 調(diào)用成員函數(shù) read可實現(xiàn)無格式輸入。它有兩個參數(shù)。第一個參數(shù)是一個指向字符的指針,第二個參數(shù)是一個整型值。這個函數(shù)把一定量的字節(jié)從輸入緩沖區(qū)讀入字符數(shù)組,不管這些字節(jié)包含的是什么內(nèi)容。 例如: char buffer[80] ; (buffer, 10 ); 讀入 10個字節(jié),放入 buffer ? 如果還沒有讀到指定的字符數(shù),遇到了 EOF,則讀操作結(jié)束。此時可以用成員函數(shù) gcount統(tǒng)計輸入的字符個數(shù) 《 程序設(shè)計 》 程序設(shè)計 38 include iostream using namespace std。 int main() {char buffer[ 80 ]。 cout Enter a sentence:\n。 ( buffer, 20 )。 cout \nThe sentence entered was:\n。 ( buffer, () )。 cout endl。 cout 一共輸入了 () 個字符 \n。 return 0。 } 《 程序設(shè)計 》 程序設(shè)計 39 輸出結(jié)果: Enter a sentence: Using the read, write, and gcount member functions The sentence entered was: Using the read,write 一共輸入了 20個字符 《 程序設(shè)計 》 程序設(shè)計 40 基于控制臺的 I/O 輸出流 輸入流 格式化輸入 /輸出 《 程序設(shè)計 》 程序設(shè)計 41 格式化輸入 /輸出 ? C++提供了大量的用于執(zhí)行格式化輸入 /輸出的流操縱算子和成員函數(shù)。 ? 功能 : 整數(shù)流的基數(shù): dec、 oct、 hex和 setbase 設(shè)置浮點數(shù)精度 :precision、 setprecision 設(shè)置域?qū)?:setw、 width 設(shè)置域填充字符 :fill、 setfill 《 程序設(shè)計 》 程序設(shè)計
點擊復(fù)制文檔內(nèi)容
教學(xué)課件相關(guān)推薦
文庫吧 www.dybbs8.com
備案圖鄂ICP備17016276號-1