unix臨時檔案建立

2021-07-28 06:01:47 字數 780 閱讀 9520

/* 看例子,建立乙個檔案,在unlink,檔案i節點的鏈結數變為0,但持有該檔案的控制代碼,依然可以fgets和fputs該檔案,說明檔案的資料塊依然存在,在fclose之後,才徹底刪除,這就是使用臨時檔案的原理 */

#include#include#include#include#include/* setvbuf實現setbuf,僅供參考 */

void setbuf(file *fp, char *buf)

else

else

}}int main(int argc, char *argv)

; file = fopen(argv[1], "w+");

if (eof == fputs("adfadsf\n", file))

{ std::cout<<"puts error"<

/* 再看乙個例子 */

#include#include#include#include#includeint main(int argc, char *argv)

{ if (argc != 2)

{ std::cout<<"param error"/* 臨時檔案舉例 */

#include#include#include#includeint main(int argc, char *argv)

{ file *file = tmpfile();

struct stat buf;

fstat(fileno(file), &buf);

std::cout<<"tmp file st_nlink:"<

C 建立臨時檔案

1.在臨時檔案只能夠建立乙個臨時檔案並返回該檔案的完整路徑 在臨時檔案只能夠建立乙個臨時檔案並返回該檔案的完整路徑 c documents and settings yourname local settings temp t e6.tmp system.io.path.gettempfilenam...

C建立臨時檔案

前言 linux下除了有實實在在的檔案外,還可以建立臨時的檔案和目錄,這裡介紹兩個建立臨時檔案的函式,tmpfilef和mkstemp,以及建立臨時目錄的函式mkdtemp。這三個函式具體用法如下。一 建立乙個無名的臨時檔案,程式退出時關閉臨時檔案 1 標頭檔案 include 2 函式原型 fil...

windows API 建立臨時檔案

建立完臨時檔案後,即可用c c 標準函式寫入 讀取,也可以用api mfc方法來操作。tchar szpathname max path tchar szfilename max path 獲得臨時檔案目錄 if gettemppath max path,szpathname 建立臨時檔名並在目錄中...