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

正文內(nèi)容

第9章c的輸入和輸出-資料下載頁

2025-07-21 23:52本頁面
  

【正文】 e()函數(shù)也是流類中的成員函數(shù),它不帶參數(shù),不返回值。 例如 : ()。 將關閉與流 out相聯(lián)接的文件。 文件的讀寫 一旦文件打開了,從文件中讀取文本數(shù)據(jù)與向文件中寫入文本數(shù)據(jù)都十分容易,只需使用運算符“ ”與“ ”就可以了,只是你必須用與文件相聯(lián)接的流代替 cin和cout。 例 把一個整數(shù)、一個浮點數(shù)和一個字符串寫到磁盤文件 test中。 include int main() { ofstream fout(test)。 if (!fout) { coutCannot open output file\n,。 return 1。 } fout10 \ This is a text file.\\n。 ()。 return 0。 } (1) 用 get()函數(shù)和 put()函數(shù)讀寫二進制文件 get()函數(shù)有許多格式,其中最常用的版本原型如下 : istreamamp。 get(charamp。 ch)。 get()函數(shù)從相關流中只讀一個字節(jié),并把該值放入ch中并返回該流,當?shù)竭_文件尾時,使該流的值為 0。 put()函數(shù)的原型如下 : ostreamamp。 put(char ch)。 put()函數(shù)將 ch寫入流中并返回該流。 例 將 ‘ a’ 至 ‘ z’ 的 26個英文字母寫入文件 , 而后從該文件中讀出并顯示出來 。 include include void test_write() { ofstream fs(d:\\)。 int i。 char c=39。a39。 for (i=0。i26。i++){ (c)。 c++。 } } void test_read() { ifstream fs(d:\\)。 char c。 while((c)) coutc。 } void main() { test_write()。 test_read()。 } (2) 用 read()函數(shù)和 write()函數(shù)讀寫二進制文件 read()和 write()原型如下 : istream amp。read(unsigned char* buf, int num)。 ostream amp。write(const unsigned char* buf,int num)。 例 912 用 write()函數(shù)向文件 test中寫入整數(shù)與雙精度數(shù) 。 include include include main() { ofstream out(test)。 if (!out) { coutCannot open output file.\n。 return 1。 } int i=12340。 double num=。 ((char *) amp。i,sizeof(int))。 ((char *) amp。num,sizeof(double))。 ()。 return 0。 } (3) 檢測文件結束 在文件結束的地方有一個標志位,記為 EOF(End OF)。采用文件流方式讀取文件時,使用成員函數(shù) eof(),可以檢測到這個結束符。如果該函數(shù)的返回值非零,表示到達文件尾。為零表示未到達文件尾。該函數(shù)的原型是 : int eof()。 函數(shù) eof()的用法示例如下 : ifstream ifs。 … if (!()) //尚未到達文件尾 … (4) 文件的隨機讀寫 在 C++的 I/O系統(tǒng)中有個文件指針,它有兩個名字。 其中一個名字叫 get指針,用于指出下一次輸入操作的位置 。 另一個名字叫做 put指針,用于指出下一次輸出操作的位置。 例 將文件 test中第五個字符修改成 X 。 include include void main(void) { fstream fs。 (d:\\test,ios::in| ios::out)。 // 以讀寫方式打開文件 if (()) coutopen file errer!。 else { (4,ios::beg)。 // 設置寫指針 (39。X39。)。 char contents[10]。 (0,ios::beg)。 // 設置讀指針 (contents,10)。 coutcontents。 } }
點擊復制文檔內(nèi)容
規(guī)章制度相關推薦
文庫吧 www.dybbs8.com
備案圖鄂ICP備17016276號-1