w 與r 等的區別

2021-06-17 19:18:51 字數 762 閱讀 7477

r+: open for reading and writing.  the stream is positioned  at  the beginning of the file.

w+:open for reading and writing.  the file is created  if  it  does not  exist, otherwise it is truncated.  the stream is positioned at the beginning of the file.

r+具有讀寫屬性,從檔案頭開始寫,保留原檔案中沒有被覆蓋的內容;

w+具有讀寫屬性,寫的時候如果檔案存在,會被清空,從頭開始寫。

r 開啟唯讀檔案,該檔案必須存在。 

r+ 開啟可讀寫的檔案,該檔案必須存在。 

w 開啟只寫檔案,若檔案存在則檔案長度清為0,即該檔案內容會消失。若檔案不存在則建立該檔案。 

w+ 開啟可讀寫檔案,若檔案存在則檔案長度清為零,即該檔案內容會消失。若檔案不存在則建立該檔案。 

a 以附加的方式開啟只寫檔案。若檔案不存在,則會建立該檔案,如果檔案存在,寫入的資料會被加到檔案尾,即檔案原先的內容會被保留。 

a+ 以附加方式開啟可讀寫的檔案。若檔案不存在,則會建立該檔案,如果檔案存在,寫入的資料會被加到檔案尾後,即檔案原先的內容會被保留。 

上述的形態字串都可以再加乙個b字元,如rb、w+b或ab+等組合,加入b 字元用來告訴函式庫開啟的檔案為二進位制檔案,而非純文字檔案。不過在posix系統,包含linux都會忽略該字元。

fopen中r 和w 的區別

原文 r open for reading and writing.the stream is positioned at the beginning of the file.w open for reading and writing.the file is created if it does ...

fopen中r 和w 的區別

2010 12 23 11 30 29 分類 c函式 標籤 fopen中r 和w 的區別 舉報 字型大小訂閱 r open for reading and writing.the stream is positioned at the beginning of the file.w open for...

n與 r的區別

r 是回車,n 是換行,前者使游標到行首,後者使游標下移一格。通常用的enter是兩個加起來。回車和換行 今天,我總算搞清楚 回車 carriage return 和 換行 line feed 這兩個概念的來歷和區別了。在計算機還沒有出現之前,有一種叫做電傳打字機 teletype model 33...