C C WIN32 三種方式實現讀寫檔案

2021-08-21 05:14:18 字數 795 閱讀 8313

/************c**************/

#include "stdafx.h"

#include

#include

#include

#define max_line 1024   //定義txt中最大行數。可調整更改

using namespace std;

int main()

; /*緩衝區*/

file *fp,*fw;           /*檔案指標*/

fopen_s(&fp,"test.txt", "r");

fopen_s(&fw,"a.txt", "r+");//r+可以選擇位置,a只能在最後加入內容,w會清空原來內容

if (fp == null)

fseek(fw, -100, seek_end);   //從哪個位置讀取  位元組偏移量set,cur,end

while (fgets(buf, max_line, fp) != null)

fclose(fp);

fclose(fw);

system("pause");

return 0;

/*****************c++**************/

/************win32************/

#include "stdafx.h"

#include

#include

using namespace std;

int _tmain(int argc,_tchar *argv)

讀寫建議的三種方式

一 bufferedinputstream bufferedoutputstream 快取位元組流 使用方式和位元組流差不多,但是效率更高 推薦使用 try 清楚快取 out.flush 關閉流 in.close out.close catch exception e 二 bufferedreade...

json三種實現方式

size large 使用ajax的開發專案過程中,經常需要將json格式的字串返回到前端,前端解析成js物件 json ecma 262 e3 中沒有將json概念寫到標準中,還好在 ecma 262 e5 中json的概念被正式引入了,包括全域性的json物件和date的tojson方法。1,e...

cmdb實現三種方式

為什麼要做cmdb?1 實現運維自動化,cmdb是實現運維自動化的基石 2 之前做資產統計的時候,使用execl來統計,為了年底資產審計方便 3 運維日常工作繁瑣,4 執行環境不統一 agent方式實現 agent方式,可以將伺服器上面的agent程式作為定時任務,定時將資產資訊提交到指定api錄入...