文件读写格式例题:
编号为p1000的求两个数的和的free pascal c++ c 三种语言解答样例:
C++ Code:
-------------------
#include <bits/stdc++.h>
using namespace std;
int main(){
freopen("p1000.in","r",stdin);
freopen("p1000.out","w",stdout);
int a,b;
cin>>a>>b;
cout<<a+b<<endl;
fclose(stdin);
fclose(stdout);
return 0;
}
Free Pascal Code:
-------------------
var a,b:longint;
begin
assign(input,'p1000.in');
assign(output,'p1000.out');
reset(input);
rewrite(output);
readln(a,b);
writeln(a+b);
close(input);
close(output);
end.
C Code:
-------------------
#include<stdio.h>
#include<stdlib.h>
int main(){
int a,b,c;
FILE *fin = fopen("P1000.in","r");
FILE *fout = fopen("P1000.out","w+");
fscanf(fin,"%d%d",&a,&b);
c=a+b;
fprintf(fout,"%d",c);
close(fin);
close(fout);
return 0;
}
( ) |