c+和c語言文件操作全高效與簡(jiǎn)潔_第1頁
c+和c語言文件操作全高效與簡(jiǎn)潔_第2頁
c+和c語言文件操作全高效與簡(jiǎn)潔_第3頁
c+和c語言文件操作全高效與簡(jiǎn)潔_第4頁
c+和c語言文件操作全高效與簡(jiǎn)潔_第5頁
全文預(yù)覽已結(jié)束

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、#include stdio.h?int main()FILE *fp,*f;?int a,b,c;?fp=fopen(apple1.txt,r);?f=fopen(apple2.txt,w);?fscanf(fp,%d%d%d,&a,&b,&c);?a=5;?b=3;?fprintf(f,%d?%d,a+b+c,b);?fclose(fp);?fclose(f);?return 0;2.txt文件,按例二、新建一個(gè)名為1.txt的文件,里面按如圖1存儲(chǔ)6個(gè)數(shù)據(jù),然后在同一目錄下建立一圖2格式輸出這六個(gè)數(shù)據(jù)。#include stdio.hint main()FILE *fp,*fpp;int

2、 a,b,c,d,e,f;fp=fopen(1.txt,r);fpp=fopen(2.txt,w);fscanf(fp,%d%d%d%d%d%d,&a,&b,&c,&d,&e,&f);fprintf(fpp,%d %d %d %d %d %d,a,b,c,d,e,f);fclose(fp);fclose(fpp);return 0;C+常用:#include ifstream filein( data.in );/ 定義一個(gè)文件輸入流ofstream fileout( data.out ); cout fileout都要改成filein, cout都要改成fileoutc語言常用:freope

3、n( date.in , r ,stdin); /重定向所有標(biāo)準(zhǔn)的輸入為文件輸入freopen( date.out , w ,stdout);重定向所有標(biāo)準(zhǔn)的輸出為文件輸出fclose(stdout); / 輸出結(jié)束freopen( date.in , r ,stdin); /重定向所有標(biāo)準(zhǔn)的輸入為文件輸入freopen( date.out , w ,stdout);重定向所有標(biāo)準(zhǔn)的輸出為文件輸出fclose(stdout); / 輸出結(jié)束第一句的意思就是文件輸入,以讀狀態(tài),去替換標(biāo)準(zhǔn)的輸入以上如果只是規(guī)定用文件輸入輸出的某一種,那么就只用其中的一種方法一:最簡(jiǎn)單的main()freopen(

4、in.txt,r,stdin);/ 從 in.txt 中讀取數(shù)據(jù)freopen(out.txt,w,stdout);/ 輸出到 out.txt 文件方法二:速度比第一種快main()FILE *in;FILE *out;in=fopen(a.txt,r); /指針指向輸入文件out=fopen(b.txt,w);/ 輸出文件格式fscanf(in,%d,&temp);/讀取文件中的數(shù)據(jù)fprintf(out,%d ,temp);fclose(in);/關(guān)閉文件流fclose(out);/關(guān)閉文件流#include #include using namespace std; int main()

5、int i,j;int n,m;static int a1024,v1024,w1024;scanf(%d%d,&n,&m);for(i=0;in;i+)scanf(%d”,&vi);for(i=0;in;i+)scanf(%d”,&wi);for(i=0;i=vi;j-)aj=max(aj,aj-vi+wi);printf(%d,am);return 0;)標(biāo)準(zhǔn)c語言#include #include using namespace std; const int MAXN = 10000; int aMAXN = 0; int main()FILE *fin, *fout;fin = fre

6、open(y.in, r, stdin);fout = freopen(y.out, w, stdout); int n = 0;fscanf(fin, %d, &n);for(int i = 0; i n; +i)fscanf(fin, %d, &ai);sort(a, a + n);for(int i = 0; i n; +i)fprintf(fout, %d , ai);fclose(fin);fclose(fout);return 0;標(biāo)準(zhǔn) c+#include #include using namespace std; const int MAXN = 10000; int aMAXN = 0;int main()ifstream fin(x.in);ofstream fout(x.out);int n = 0;fin n;for(int i = 0;

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論