C 學習筆記day 18檔案操作

2021-10-09 05:42:17 字數 1544 閱讀 8287

1、文字檔案–寫檔案

#include

#include

using

namespace std;

//文字檔案 寫檔案

void

test01()

intmain()

2、文字檔案–讀檔案

#include

#include

#include

using

namespace std;

//文字檔案 讀檔案

void

test01()

//4、讀資料

//第一種

//char buf[1024] = ;

/*while (ifs >> buf)

*///第二種

/*while (ifs.getline(buf, sizeof(buf)))

*///第三種

/*string buf;

while( getline(ifs,buf)) */

//第四種

char c;

while

((c = ifs.

get())

!=eof

)//eof end of file

//5、關閉檔案

ifs.

close()

;}intmain()

3、二進位制檔案–寫檔案

#include

#include

using

namespace std;

//二進位制檔案 寫檔案

class

person

;void

test01()

; ofs.

write((

const

char*)

&p,sizeof

(person));

//5、關閉檔案

ofs.

close()

;}intmain()

4、二進位制檔案–讀檔案

#include

#include

using

namespace std;

//二進位制檔案 寫檔案

class

person

;void

test01()

//4、讀檔案

person p;

ifs.

read((

char*)

&p,sizeof

(person));

cout <<

"姓名:"

<< p.m_name << endl;

cout <<

"年齡:"

<< p.m_age << endl;

//5、關閉檔案

ifs.

close()

;}intmain()

day18 檔案處理b(byte)模式

檔案處理的byte模式 f open test2.py 函式預設是 rb 模式,即為讀取模式 讀取乙個byte模式的檔案 rbf open test2.py rb 前提是存在這個可操作的物件 data f.read print data 列印出來的是byte二進位制的模式 print data.de...

18 檔案操作

1.了解檔案操作 思考 什麼是檔案?思考 檔案操作包含什麼?答 開啟,關閉,讀,寫,複製 思考 檔案操作的作用是什麼?答 讀取內容,寫入內容,備份內容.總結 檔案操作的作用就是把一些內容 資料 儲存存放起來,可以讓程式下一次執行的時候直接使用,而不必重新製作乙份,省時省力。2.檔案的基本操作 開啟檔...

python學習筆記 day18 初識模組

正規表示式其實和python並沒有什麼關係,它就是字串匹配的規則 字元組 在同乙個位置可能出現的各種字元就組成了乙個字元組,比如你要求乙個位置只能出現數字,但是這個數字可以是0 9之間的任意乙個,這個時候就可以用到正則了 0123456789 相當於 0 9 可以匹配0 9之間的任意乙個數字 a z...