使用文件最简单的方式就是使用输入输出重定向

freopen("input.txt","r",stdin);//从文件读入
freopen("outout.txt","w",stdout);//写入文件

非重定向

#include<stdio.h>
int main()
{
	FILE *fin,*fout;
	int x;
	fin = fopen("input.txt","rb");//从文件读入
	fout = fopen("outout.txt","wb");//写入文件
	fscanf(fin,"%d",&x);
	fprintf(fout,"%d",x);
	fclose(fin);
	fclose(fout);
	return 0;
}